我正在尝试写一个应用程序,它列出了从服务器上的文件。现在,我想让用户使用任何编辑器打开列表(Windows)中的任何文件,例如,一个文本文件,用户使用NotePad++打开。
现在有没有什么我可以知道的,如果用户保存了文件,如果是,那么我会将文件上传回服务器。
发布于 2013-05-22 20:42:27
有一个关于Watching a Directory for Changes的教程描述了Java7中引入的WatchService。您可以使用此服务来监控文件和目录:
WatchService watcher = FileSystems.getDefault().newWatchService();
Path dir = ...;
try {
WatchKey key = dir.register(watcher,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
} catch (IOException x) {
System.err.println(x);
}发布于 2013-05-22 20:40:37
使用File#lastModified()获取上次修改文件的时间。
https://stackoverflow.com/questions/16691975
复制相似问题