我尝试用Java启动vlc播放器,但不知怎的,它没有说出来。 我尝试过的任何其他Prog都有效。 Plz看看我的代码:
try {
Runtime.getRuntime().exec("K:\\...\\vlc.exe");
} catch (Exception ex) {
System.out.println(ex);
}
启动videoLAN Player的问题在哪里?
答案 0 :(得分:1)
事实仍然是,你有一个错误,你不知道它是什么。我的建议是将stderr
流与监听线程正确连接(至少!),这样你就会看到程序向你抛出的错误信息。
答案 1 :(得分:1)
Javacode:
import java.io.*;
public class Test {
public static void main(String args[]) {
new Test("K:/Programms/VideoLAN/VLC/vlc.exe");
}
public Test(String path) {
File f = new File(path);
if (!(f.exists()&&f.isFile())) {
System.out.println("Incorrect path or not a file");
return;
}
Runtime rt = Runtime.getRuntime();
try {
Process proc = rt.exec(path);
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), false);
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), false);
errorGobbler.start();
outputGobbler.start();
System.out.println("\n"+proc.waitFor());
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
class StreamGobbler extends Thread {
InputStream is;
boolean discard;
StreamGobbler(InputStream is, boolean discard) {
this.is = is;
this.discard = discard;
}
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
if(!discard)
System.out.println(line);
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
答案 2 :(得分:0)
你需要检查确保各种事情。
答案 3 :(得分:0)
实际上你在代码中犯了一个错误,runtime类的exec()方法返回java.lang.Process所以你应该在你的代码中使用一个返回类型,所以试试这个代码...........
try {
process ps=Runtime.getRuntime().exec("K:\\...\\vlc.exe");
} catch (Exception ex) {
System.out.println(ex);
}