How can i call an external file in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i call an external file in java?

say i want to call a pdf when someone click a button in java , what is the required exec code for that?

20th Feb 2017, 3:56 AM
Pritish Mishra
Pritish Mishra - avatar
1 Answer
+ 3
For that, you'll need to import the File, IOException, and Desktop libraries: import java.io.File; import java.io.IOException; import java.awt.Desktop; Then, somewhere in the body of your code, try: Desktop d = Desktop.getDesktop(); File pdf = new File("C:\path\to\file"); After that, call d.open() with pdf as the argument. Make sure you do this within a try-catch block, because it could throw an IOException if the file path is invalid.
20th Feb 2017, 4:53 AM
DaemonThread
DaemonThread - avatar