2

我正在制作一个程序,它是游戏私人服务器的启动器。如果我更改服务器,我必须更改客户端,所以我希望它只下载更改的文件,而不是覆盖旧文件。我正在使用保管箱来存储文件。我怎样才能做到这一点?

4

3 回答 3

3

在 Java 7 中,您可以使用WatchService获取通知

使用此 API,您可以注册各种事件

ENTRY_CREATE – A directory entry is created.
ENTRY_DELETE – A directory entry is deleted.
ENTRY_MODIFY – A directory entry is modified.
OVERFLOW – Indicates that events might have been lost or discarded. You do not have to register for the OVERFLOW event to receive it.

以下代码片段显示了如何为所有三种事件类型注册 Path 实例:

import static java.nio.file.StandardWatchEventKinds.*;

Path dir = ...;
try {
WatchKey key = dir.register(watcher,
                       ENTRY_CREATE,
                       ENTRY_DELETE,
                       ENTRY_MODIFY);
} catch (IOException x) {
 System.err.println(x);
}

使用 WatchEvent,您可以调用适当的通知到您的应用程序文件已更改并下载它

于 2012-08-29T09:43:09.993 回答
1

使用数据库在服务器端维护文件版本或进行校验和以识别修改后的文件

于 2012-08-29T09:41:14.183 回答
0

I'd start by taking a look at the Dropbox SDK

I'd also make sure that each file on the server has a MD5 (other checksum) associated with it. You could download these checksums and compare them to the files you have installed on your local machine. If any of the checksums are different, then you can download the file you need.

Have a look at How can I generate an MD5 hash? and How do I generate an MD5 digest for a file

于 2012-08-29T09:48:23.077 回答