- 我想使用Java程序将AVI文件转换为3GP。
- 为此,我正在使用“E.M. Total Video Converter Command Line 2.43”,其命令为:
"C:\E.M. TVCC>TVCC -f E:\TestVideo\01.avi -o E:\OutputFiles\target.3gp" - 我在http://www.rgagnon.com/javadetails/java-0014.html网站上找到了一个执行命令行可执行文件的程序,代码如下:
路径包含空格的可执行文件
如果路径中包含空格,在Windows平台上,您需要用引号将路径括起来以便正确执行程序。
public class Test {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec(
"\"c:/program files/windows/notepad.exe\"");
p.waitFor();
}
}
如果需要传递参数,使用字符串数组会更安全,特别是当参数中包含空格时。
String[] cmd = { "myProgram.exe", "-o=This is an option" };
Runtime.getRuntime().exec(cmd);
如果使用 "start" 命令并且要启动的文件路径中包含空格,则必须在"start"命令中指定一个标题。String fileName = "c:\\Applications\\My Documents\\test.doc";
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
Runtime.getRuntime().exec(commands);
有人能帮助我将上述命令放入这段代码中吗?我不知道在上面的代码中放置该命令的语法规则。请帮帮我。
这就是我使用的确切Java代码:
public class Test {
public static void main(String[] args) throws Exception {
String[] cmd = { "C:\\Program Files\\E.M. TVCC\\TVCC.exe", "-f C:\\Program Files\\E.M. TVCC\\01.avi", "-o C:\\Program Files\\E.M. TVCC\\target.3gp" };
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
}
}