# \[SOLVED\] Is there any way to open a file through programming,, not like a file handling?

**URL:** <https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876>\
**Category:** Discussion & Solutions\
**Tags:** solved\
**Created:** [October 7, 2019, 11:59am UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876 "2019-10-07T11:59:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bikash\_Gurung](https://onehack.st/user_avatar/onehack.st/bikash_gurung/32/18359_2.png) [@Bikash\_Gurung](https://onehack.st/u/Bikash_Gurung)\
**Post date:** [October 7, 2019, 11:59am UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876/1 "2019-10-07T11:59:58Z")

</div>

Is it possible to open a file through programming? Not like a file handling… But when a programs runs… it should automatically open a given file.. just like when we click on that file.

---

<div class="post-metadata">

**Author:** ![kannan](https://onehack.st/letter_avatar_proxy/v4/letter/k/7ba0ec/32.png) [@kannan](https://onehack.st/u/kannan)\
**Post date:** [October 7, 2019, 12:58pm UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876/2 "2019-10-07T12:58:37Z")

</div>

Which programming language u r using?  
Most of them already available in YouTube or Google.  
Or be more specific on your requirement.

---

<div class="post-metadata">

**Author:** ![Alankar](https://onehack.st/user_avatar/onehack.st/alankar/32/21442_2.png) [@Alankar](https://onehack.st/u/Alankar)\
**Post date:** [October 7, 2019, 1:45pm UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876/3 "2019-10-07T13:45:11Z")

</div>

Below is JAVA code, let me know if it helped

package open;

import java.awt.Desktop;  
import java.io.File;  
import java.io.IOException;

public class Open {  
public static void main(String args) {  
if (Desktop.isDesktopSupported()) {  
try {  
File myFile = new File(“path of your file eg: C:\newfolder\myfile.extension”);  
Desktop.getDesktop().open(myFile);  
} catch (IOException ex) {  
// no application registered for file you are opening  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![TheJoker](https://onehack.st/user_avatar/onehack.st/thejoker/32/22660_2.png) [@TheJoker](https://onehack.st/u/TheJoker)\
**Post date:** [October 7, 2019, 9:41pm UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876/4 "2019-10-07T21:41:15Z")

</div>

## There are Many scripting languages will do this. PowerShell for instance. Perl also in some instances, though Perl offers full features for explicitly opening files as well.

- In PowerShell I can read process and rewrite a file with something as simple as this:

`import-csv file.csv | where {$_.status -eq ‘important’} | export-csv new-file.csv`

**The original file is implicitly opened then read and implicitly closed, while the same thing happens to the new file when the content is written.**

---

<div class="post-metadata">

**Author:** ![Alankar](https://onehack.st/user_avatar/onehack.st/alankar/32/21442_2.png) [@Alankar](https://onehack.st/u/Alankar)\
**Post date:** [October 8, 2019, 5:55am UTC](https://onehack.st/t/solved-is-there-any-way-to-open-a-file-through-programming-not-like-a-file-handling/59876/5 "2019-10-08T05:55:50Z")

</div>

**If you are working in windows and do not want to install any compiler then the batch file programming or the VBS is the best option, it is used in windows automation as well..**
