[英]Resource files in a Java program
我希望能够运行在我的 java 应用程序中编译的 bat 文件。 在 netbeans IDE 中一切正常,但是当我构建并运行时,cmd 无法运行捆绑在 jar 文件中的资源文件。 我用cmd(Java中的运行时)运行bat文件。 从下图中,应用程序包是apksec,其他是资源文件夹,里面有我想在程序中使用的文件,bat文件在res文件夹中,当我直接从cmd运行应用程序时
C:\Users\slab1>java -jar C:\Users\slab1\Pictures\training\dist\ApkSec.jar
我得到错误
'file:' is not recognized as an internal or external command,
使用下面的 cmd 运行 bat 文件的代码片段
我如何获得运行jar中捆绑资源文件的路径?
请注意您传递给 exec 方法的参数。 这里是一个例子 - https://www.tutorialspoint.com/java/lang/runtime_exec_envp.htm
public static void main(String[] args) {
try {
// create a new array of 2 strings
String[] cmdArray = new String[2];
// first argument is the program we want to open
cmdArray[0] = "notepad.exe";
// second argument is a txt file we want to open with notepad
cmdArray[1] = "example.txt";
// print a message
System.out.println("Executing notepad.exe and opening example.txt");
// create a process and execute cmdArray and currect environment
Process process = Runtime.getRuntime().exec(cmdArray,null);
// print another message
System.out.println("example.txt should now open.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.