Java-在NB平台应用程序中从同一个包加载文件
我有下面的代码Java-在NB平台应用程序中从同一个包加载文件,java,file,netbeans,netbeans-platform,Java,File,Netbeans,Netbeans Platform,我有下面的代码 public void vbsCalled() { try { String file = "src\\com\\first\\hello\\hello.vbs"; Runtime.getRuntime().exec("wscript " + file + " "); } catch (IOException ex) { Logger.getLogger(RunVBS.clas
public void vbsCalled() {
try {
String file = "src\\com\\first\\hello\\hello.vbs";
Runtime.getRuntime().exec("wscript " + file + " ");
} catch (IOException ex) {
Logger.getLogger(RunVBS.class.getName()).log(Level.SEVERE, null, ex);
}
}
我正在使用netbeansIDE
场景1:
--Java Application1
-Source Packages
-com.first.hello //Package
-ClassWhichHaveVbsCalledMethod.java
-hello.vbs
有了这个,我可以从同一个包调用hello.vbs,并且没有错误
场景2:
--Java Application1
-Source Packages
-com.first.hello //Package
-ClassWhichHaveVbsCalledMethod.java
-hello.vbs
RunVBS.java
具有vbscaled()
方法,并与场景1在同一个包中使用hello.vbs
现在,它在中查找文件
“C:\application1\src\com\first\hello\hello.vbs”
并显示未发现此类文件错误
如何像场景1一样在netbeans平台应用程序中加载文件
public void vbsCalled() {
try {
File file = InstalledFileLocator.getDefault().locate(
"hello.vbs", // filename relative to the release/ directory
"com.first.hello", // Your module's code name base __not package!__
false);
Runtime.getRuntime().exec("wscript " + file.getAbsolutePath() + " ");
} catch (IOException ex) {
Logger.getLogger(RunVBS.class.getName()).log(Level.SEVERE, null, ex);
}
}
有关更多详细信息,请参阅