Background
I have an old applet that I want to revive. All functionality works in Windows XP. However, in Windows 7 it doesn’t work to open a file in its native application (part of code below). Nothing happens, no error or anything similar. I am using Java version 1.5.0 (J2SE 5.0), thus Desktop.getDesktop(); will not work!
Code
public void start(String sFileName, String sDir, ctgraphics gGfx) {
String command = '"' + sDir + sFileName + '"';
Runtime myRuntime = Runtime.getRuntime();
try {
myRuntime.exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + command);
gGfx.setStatusText("File opened.");
gGfx.drawStatusBar(1);
} catch (IOException e) {
System.out.println("Error " + e.getMessage());
}
}
Question
Why doesn’t the above code work in Windows 7 and what do I need to do instead to be able to open a file in its native application (considering I am using Java v. 1.5) ?
.
Cheers.
You may want to use the Desktop support, look at this link:
Desktop.open
You just create a
Filewith the path of the file you want to open and then callDesktop.getDesktop().open(file).Before 1.5 desktop was a Library that then it made it into the standard JDK, you can consider using this option.
Here you can find a tutorial:
javadesktop tutorial for java one 2004
Hope this helps
And here is the project site:
JDIC Project
Here you can find the jars:
Maven repo with jdic jars