如何使用Java检测Google Drive中是否存在文件(而不是使用Java)? [英] How to detect if file exists in Google Drive (and not trashed) using Java?

查看:208
本文介绍了如何使用Java检测Google Drive中是否存在文件(而不是使用Java)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

漂亮的不言自明的标题。我正在使用Google Drive Client API for Java。我现在有如下所示:

 文件f = mService.files.get(fileId).execute(); 

但是,我找不到 File 用于检查文件是否被删除。 File.getExplicitlyTrashed()对于已删除的文件和未删除的文件都给出了空值。

解决方案

已损坏属性隐藏在 File.Labels class ,您可以从 File.getLabels() 。一个可行的例子是:

$ $ $ $ $ $ $ $ $ $ $ $文件f = 。mService.files()得到(ID).execute();
return!f.getLabels()。getTrashed();
} catch(IOException e){
e.printStackTrace();
System.out.println(bad id:+ id);
}
返回false;
}


Pretty self-explanatory title. I'm using Google Drive Client Api for Java. What I currently have is as follows:

File f = mService.files.get(fileId).execute();

However, I can't find the property in File used to check if a file is trashed or not. File.getExplicitlyTrashed() gives me null for both trashed and not trashed files.

解决方案

The trashed property is hidden inside the File.Labels class, which you can get from File.getLabels(). A working example is:

public boolean validFileId(String id) {
    try {
        File f = mService.files().get(id).execute();
        return !f.getLabels().getTrashed();
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("bad id: " + id);
    }
    return false;
}

这篇关于如何使用Java检测Google Drive中是否存在文件(而不是使用Java)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆