我想在Mac运行时使用netbeans打开应用程序,我使用了下面的代码,但它引发异常。我使用这个代码的窗口与我在Mac中使用它的几个变化。任何人都可以告诉我正确的代码。使用netbeans在Mac OSX运行时在运行时打开应用程序
else
{
try {
Runtime r = Runtime.getRuntime();
p = Runtime.getRuntime().exec("/Applications/TextEdit.app /Users/apple/Documents/java files/scratch files/hi.rtf");
A4 a4sObj = new A4(new String[]{jComboBox2.getSelectedItem().toString()});
} catch (IOException ex) {
Logger.getLogger(serialportselection.class.getName()).log(Level.SEVERE, null, ex);
}
}
你可以使用'Desktop.edit'如果你想调用的“默认”的编辑器文件,请参阅[如何与桌面类集成](https://docs.oracle.com/javase/tutorial/uiswing/misc/desktop.html)以获取更多详细信息 – MadProgrammer
假设我想打开任何其他应用程序不是默认的,那么这个类对我来说不会有帮助 –
Mac应用程序只是一个特殊的“文件夹”,所以你不能“运行”它们,而是你需要查看应用程序包的Contents/MacOS目录),这可能更像'/ Applications/TextEdit.app/Contents/MacOS/TextEdit'。我也建议直接在'Process'上使用'ProcessBuilder' – MadProgrammer