public class Test{ public static void main(String[] args) {
try{
String shellString = "lame -b 16 /java/5/a.wav /java/5/a.mp3";
String[] cmd = new String[]{"sh","-c",shellString}; Process process = Runtime.getRuntime().exec(cmd);
//Process process=Runtime.getRuntime().exec("lame -b 16 /java/5/a.wav /java/5/a.mp3"); // lame 你的.wav文件,简易版
process.waitFor(); //阻塞,直到上述命令执行完,一定要在文件close()关闭前面
process.getOutputStream().close();
process.getInputStream().close();
process.getErrorStream().close();
}catch (Throwable e){ } } }
解决java使用Runtime.exec执行linux命令不成功问题
关键问题在于 waitFor( ) ; 关于更多解释 , 请看 http://lelglin.iteye.com/blog/1487351