在保留文件的修改日期时,有没有办法可以从/下载/下载文件?

发布于 2025-01-30 16:36:51 字数 1165 浏览 1 评论 0 原文

我正在尝试为我的写作应用程序构建同步系统,以便我可以将文本文件与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(); }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡忘如思 2025-02-06 16:36:51

You can set the clientModified date using UploadBuilder.withClientModified. It's not possible to override the serverModified date though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文