Java程序中的资源文件
我希望能够运行在java应用程序中编译的bat文件。在netbeans IDE中,一切都可以正常运行,但是当我构建并运行时,cmd无法运行jar文件中绑定的资源文件。l使用java中的cmdRuntime运行bat文件。从下图可以看出,应用程序包是apksec,其他是资源文件夹,其中包含我想在程序中使用的文件,bat文件位于res文件夹中, 当我直接从cmd运行应用程序时Java程序中的资源文件,java,cmd,runtime,Java,Cmd,Runtime,我希望能够运行在java应用程序中编译的bat文件。在netbeans IDE中,一切都可以正常运行,但是当我构建并运行时,cmd无法运行jar文件中绑定的资源文件。l使用java中的cmdRuntime运行bat文件。从下图可以看出,应用程序包是apksec,其他是资源文件夹,其中包含我想在程序中使用的文件,bat文件位于res文件夹中, 当我直接从cmd运行应用程序时 C:\Users\slab1>java -jar C:\Users\slab1\Pictures\training\d
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方法的参数。以下是一个例子,来自:
不要插入屏幕截图,但此处的代码GetDexToolPath将返回如下内容file://c/blahblah. 我认为你所尝试的不会奏效;您的操作系统如何运行一个在jar中有效压缩的程序?问题是getClass.getResource java函数在目录部分添加了文件://。当我删除文件时:///和!从目录路径,我得到nullpointerexception错误
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();
}
}