Java 检测文件何时保存

Java 检测文件何时保存,java,Java,我如何注意到txt文件的执行何时关闭并保存?我运行以下代码,并希望获得修改后的文件 这是我的密码 byte[] filedata = (byte[]) server.downloadFile(fileName); //geting the file File file = new File(userName+fileName+".txt"); BufferedOutputStream output = new BufferedOutputStream(new FileOu

我如何注意到txt文件的执行何时关闭并保存?我运行以下代码,并希望获得修改后的文件

这是我的密码

byte[] filedata = (byte[]) server.downloadFile(fileName);

//geting the file
File file = new File(userName+fileName+".txt");
BufferedOutputStream output = new BufferedOutputStream(new   
        FileOutputStream(file.getName()));
output.write(filedata,0,filedata.length);
output.flush();
output.close();

//file.setWritable(true);
Runtime rt = Runtime.getRuntime();
rt.exec("notepad "+userName+fileName+".txt");

然后我执行,当用户用新数据保存它时,我想在这里获取它。

rt.exec返回一个Java进程对象,该对象有一个等待进程退出的方法。我自己从未尝试过(完全披露),但我认为这应该有效:

Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad "+userName+fileName+".txt");
try {
  p.waitFor();
} catch (InterruptedException ex) {
  throw ex;
}

请将此重新格式化为可读代码。如何用颜色和所有内容发布我的代码?太好了!如果行得通,你能接受我的回答吗?谢谢