我正在尝试为我的写作应用程序构建同步系统,以便我可以将文本文件与Dropbox文件夹同步并从我的计算机中进行编辑。
事实是,当文件上传时,其修改日期对应于上传时间的日期,而不是最后一次修改文件的内容,并且看起来Dropbox文件最近比本地文件更改了Dropbox文件。下载同样的内容,因为本地版获得的修改日期比Dropbox One更新。
当我想比较日期以确定本地和网络版本之间的最新版本时,这使事情变得复杂,如果我需要上传本地版本或下载网络版本以最新。
有没有办法保留原始文件的修改日期?目前,我正在使用这些功能,但是也许我应该使用完全不同的方法。
public void uploadFile(String local_path, String db_path) {
try {
InputStream in = new FileInputStream(local_path);
client.files().uploadBuilder(db_path)
.withMode(WriteMode.OVERWRITE)
.uploadAndFinish(in);
}
catch (FileNotFoundException fne) { fne.printStackTrace(); }
catch (IOException ioe) { ioe.printStackTrace(); }
catch (DbxException dbxe) { dbxe.printStackTrace(); }
}
public void downloadFile(String db_path, String local_path) {
try {
File dest = new File(local_path);
try (OutputStream outputStream = new FileOutputStream(dest)) {
client.files().download(db_path).download(outputStream);
}
}
catch (DbxException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
}
I'm trying to build a sync system for my writing application, so that I can synchronize my text files with a Dropbox folder and edit them from my computer.
Thing is, when a file is uploaded, its modification date corresponds to that of the upload time, not the last time the file's content was modified, and it looks as if the Dropbox file was modified more recently than the local file. Same thing for download, as the local version gets a more recent modification date than the Dropbox one.
This makes things complicated when I want to compare dates to determine which version is the most recent one between the local and the network versions, and if I need to upload the local version or download the network one to be up-to-date.
Is there a way to keep the modification date of the original file ? Currently, I'm using these functions, but maybe I should use a completely different method.
public void uploadFile(String local_path, String db_path) {
try {
InputStream in = new FileInputStream(local_path);
client.files().uploadBuilder(db_path)
.withMode(WriteMode.OVERWRITE)
.uploadAndFinish(in);
}
catch (FileNotFoundException fne) { fne.printStackTrace(); }
catch (IOException ioe) { ioe.printStackTrace(); }
catch (DbxException dbxe) { dbxe.printStackTrace(); }
}
public void downloadFile(String db_path, String local_path) {
try {
File dest = new File(local_path);
try (OutputStream outputStream = new FileOutputStream(dest)) {
client.files().download(db_path).download(outputStream);
}
}
catch (DbxException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
}
发布评论
评论(1)
您可以使用 clientmodified 日期/files/uploadbuilder.html#withclientmodified(java.util.date)“ rel =“ nofollow noreferrer”>
code> uploadbuilder.withclientmodified
。不可能覆盖servermodified
日期。You can set the
clientModified
date usingUploadBuilder.withClientModified
. It's not possible to override theserverModified
date though.