好的,我花了一些时间,所以我将答案发布给其他人。
当然,您必须指定要保存它的位置(但这很明显),然后创建OutputStream
:
String path = Environment.getExternalStorageDirectory().toString() + "/DCIM";
File file = new File(path, "test.txt");
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
之后,我们创建Metadata
对象并对其进行初始化,然后使用进行下载metadata.getPathLower()
。
try {
Metadata pathMetadata = client.files().getMetadata("/test.txt");
client.files().download(pathMetadata.getPathLower()).download(outputStream);
Log.e("METADATA", pathMetadata.toString());
} catch (DbxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
奇怪的是getPathLower()
返回,"test.txt"
但是当我们在raw download()
方法内部键入它时,它返回
java.lang.IllegalArgumentException: String 'path' does not match pattern
("/test.txt"
也不起作用)。
我花了很多时间才能使它起作用,所以我希望我的回答可以帮助某人节省时间。
编码愉快!
很高兴看到您已经开始使用此功能。作为参考,“ / test.txt”当然也应该工作,因为这是正确的格式。尝试时得到了什么?(也许是拼写错误?)
getMetadata
如果您已经知道路径,则也不需要调用。getPathLower
只会返回“ /test.txt”之类的字符串(而不是“ test.txt”,因为它缺少前斜杠而无法使用)。