[英]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.