Javaでvlcプレーヤーを起動しようとしましたが、どういうわけか言葉になりませんでした。私が試した他のProgはすべて機能しました。Plzは私のコードを見てください:
try {
Runtime.getRuntime().exec("K:\\...\\vlc.exe");
} catch (Exception ex) {
System.out.println(ex);
}
videoLAN Playerの起動の問題はどこにありますか?
Javaでvlcプレーヤーを起動しようとしましたが、どういうわけか言葉になりませんでした。私が試した他のProgはすべて機能しました。Plzは私のコードを見てください:
try {
Runtime.getRuntime().exec("K:\\...\\vlc.exe");
} catch (Exception ex) {
System.out.println(ex);
}
videoLAN Playerの起動の問題はどこにありますか?
Java コード:
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();
}
}
}
}
エラーがあり、それが何であるかわからないという事実は残ります。プログラムがスローしているエラー メッセージが表示されるように、(少なくとも!)stderrストリームをリッスン スレッドに適切に接続するようにアドバイスします。
いろいろ確認する必要があります。
実際、あなたはコードを間違えました.Runtimeクラスのexec()メソッドはjava.lang.Processを返すので、コードで戻り値の型を取る必要があるので、このコードを試してください.....
try {
process ps=Runtime.getRuntime().exec("K:\\...\\vlc.exe");
} catch (Exception ex) {
System.out.println(ex);
}