String fileName = javaoutput.out
String target = "Mltexp -owprj xyz -output abc.out"
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(target);
InputStream i = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(i);
BufferedReader br = new BufferedReader(isr);
try (FileWriter fw = new FileWriter(fileName)) { // for appending use (f,true)
BufferedWriter bw = new BufferedWriter(fw);
while((br.readLine()) != null){
fw.write(br.readLine());
// You can also use append.
}
bw.flush();
} catch (IOException e) {
System.err.println("Problem writingw riting the file");
}
我需要运行一个系统命令,它具有参数“-output”来指定输出文件名。我的代码创建了一个javaoutput.out文件,显示错误“无法打开输出文件进行写入”。
我也尝试了系统命令“Mltexp -owprj xyz -output / dev / stdout”。再次javaoutput.out文件显示相同的错误“无法打开输出文件进行写入”