[英]How run a jar file which contains a call to a batch file?
I have made a java application that sometimes should call a batch file in order to move a video from a folder to another.我制作了一个 java 应用程序,有时应该调用一个批处理文件,以便将视频从一个文件夹移动到另一个文件夹。 The batch file is in the same directory of the main class of the project (ProjectName\\src\\move.bat).
批处理文件位于项目主类的同一目录中(ProjectName\\src\\move.bat)。
I got the path of the batch file through the instruction:我通过指令得到了批处理文件的路径:
String pathMoveBat = new java.io.File("src\\move.bat").getAbsolutePath();
and I use the code below (which is called by pressing a button in the application) to call that file:我使用下面的代码(通过按下应用程序中的按钮调用)来调用该文件:
Process move = Runtime.getRuntime().exec(pathMoveBat+" "+username+" "+dateFormat.format(currentDate)+" "+i+"");
Basically, when I click on the button nothing happen and seems that Windows cannot find the file move.bat.基本上,当我点击按钮时什么也没有发生,似乎 Windows 找不到文件 move.bat。
Is there any other way to call that file from a jar?有没有其他方法可以从 jar 中调用该文件?
There are some points you need to understand before make it to work在使其工作之前,您需要了解一些要点
Runtime.getRuntime().exec("cmd /c move.bat "+username+" "+dateFormat.format(currentDate)+" "+i+""); Runtime.getRuntime().exec("cmd /c move.bat "+username+" "+dateFormat.format(currentDate)+" "+i+"");
Switch to ProcessBuilder if you can, its better : https://stackoverflow.com/a/10723391/1129313如果可以,切换到 ProcessBuilder,它更好: https : //stackoverflow.com/a/10723391/1129313
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.