【发布时间】:2011-03-14 23:33:13
【问题描述】:
1)我正在使用Java调用Linux终端运行foo.exe并将输出保存在一个文件中:
String[] cmd = {"/bin/sh", "-c", "foo >haha.file"};
Runtime.getRuntime().exec(cmd);
2)问题是当我打算稍后在代码中读取haha.file时,它还没有写出来:
File f=new File("haha.file"); // return true
in = new BufferedReader(new FileReader("haha.file"));
reader=in.readLine();
System.out.println(reader);//return null
3) 程序完成后才会写入haha.file。我只知道如何刷新“作家”,但不知道如何刷新某事。像这样。 如何强制java在终端中写入文件?
提前致谢 E.E.
【问题讨论】: