Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to open a file through a java program.The file should open in the system's default program.
for e.g.:a text file should open in notepad.
an image should open in default image viewer.

what are the possible ways of implementing this?

i want to write a function to which i will pass an object of class File and the function has to open the file.

thanks
Posted

1 solution

Java
File file = new File("myFile.txt");

Desktop.getDesktop().open(file);
 
Share this answer
 
v2
Comments
ankit_khedekar 14-Aug-11 8:19am    
thanks for your reply
this is working well for all files except mp3 files.the mp3 does not play and gives an exception"unspecified error".even the videos files open perfectly in the media player classic so why dont the mp3 files

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900