我在服务器中有两个文件,一个是本地文件,我想获得两个文件的最后修改,并查看哪一个更新。我做了一个方法,但我总是得到相同的结果。我试过每一方面的测试,但if语句总是做出相同的决定。如何比较FTPClient文件的上次修改与本地文件?
这里是我的代码:
public void SyncCheck(FTPClient ftpClient, String remoteFilePath, String savePath) throws IOException, ParseException{
String time = ftpClient.getModificationTime(remoteFilePath);
Date remoteFileDate = timeSplitter(time);
Date LocalFileDate = new Date(new File(savePath).lastModified());
if(remoteFileDate.after(LocalFileDate)){
System.out.println("Remote File is newer: " + remoteFileDate);
}
else{
System.out.println("nothing");
System.out.println("Remote " + remoteFileDate);
System.out.println("Local " + LocalFileDate);
}
}
public Date timeSplitter(String time) throws ParseException{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String timePart = time.split(" ")[1];
Date modificationTime = dateFormat.parse(timePart);
return modificationTime;
}
结果总是这样:
nothing
Remote Fri Apr 03 02:20:30 BST 2015
Local Fri Apr 03 03:12:58 BST 2015
无论是远程文件更新或更旧。我注意到的另一个问题是,远程文件在03:20:30被修改,但总是落后一个小时。是关于任何时区?
或者任何想法比较一个服务器文件的最后修改时间与本地服务器文件?
你总是得到相同的修改时间吗?问题是什么? – ddarellis 2015-04-03 11:36:15
@Paner否如果我修改文件,修改时间会发生变化,但问题是服务器文件总是落后一小时。所以如果我现在修改它,它会提供一小时前的时间。所以它总是比当地时间的文件还要旧。这就是问题所在。 – Dan 2015-04-04 22:46:39