如何使用Java检测Google Drive中是否存在文件(而不是使用Java)? [英] How to detect if file exists in Google Drive (and not trashed) using 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屋!