【发布时间】:2012-05-08 04:53:30
【问题描述】:
背景
我有一个想要恢复的旧小程序。所有功能均可在 Windows XP 中运行。但是,在 Windows 7 中,无法在其本机应用程序中打开文件(下面的部分代码)。什么都没有发生,没有错误或类似的东西。我正在使用 Java 版本 1.5.0 (J2SE 5.0),因此 Desktop.getDesktop(); 将不起作用!
代码
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());
}
}
问题
为什么上面的代码在 Windows 7 中不起作用,我需要做什么才能在其本机应用程序中打开文件(考虑到我使用的是 Java v. 1.5)?
.
干杯。
【问题讨论】:
-
catch (IOException e) { ..e.getMessage()..尽管代码目前没有产生异常输出,但我建议更改最后一部分以添加:e.printStackTrace();。