gpt4 book ai didi

java - 使用运行时在其 native 应用程序中打开文件。 (Windows 7的)

转载 作者:行者123 更新时间:2023-12-01 19:05:11 25 4
gpt4 key购买 nike

背景

我有一个旧的小程序,我想恢复它。所有功能均可在 Windows XP 中使用。但是,在 Windows 7 中,无法在其 native 应用程序中打开文件(下面的部分代码)。什么也没发生,没有错误或类似的事情。我正在使用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 中不起作用?我需要做什么才能在其 native 应用程序中打开文件(考虑到我使用的是 Java v. 1.5)?

.

干杯。

最佳答案

阅读When Runtime.exec() won't 。它描述了许多常见的问题。

关于java - 使用运行时在其 native 应用程序中打开文件。 (Windows 7的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com