我有一个Android应用程序,可将图像和文本文件加载到Dropbox中。我已经弄清楚了身份验证和上传过程。
现在,使用相同的身份验证会话,我想读取一个上载的文本文件(以查找更改)。我找到了一个下载示例,但这意味着将其写入本地SD,然后在那里读取...根本没有效率(部分原因是需要额外的android许可)。
我已经检查过Dropbox's v2 documentation,并且似乎有很多读取调用,但是我一生都无法弄清楚如何使用它们。有用的Android-Dropbox examples似乎也无法解决我的特定问题。我在stackoverflow上也找不到任何v2示例。
当然,有人可以指出一个简单的示例,该示例提供了一个不错的InputStream。
答案 0 :(得分:1)
您可以使用the Dropbox Java SDK download
method直接获取文件内容。有an example of using that in the example app here。该示例直接写入FileOutputStream
。
听起来您似乎只想要InputStream
,看起来像这样:
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
String remotePath = "/test.txt"; // the path to the file you want to download
InputStream fileInputStream = null;
try {
fileInputStream = client.files().download(remotePath).getInputStream();
// use `fileInputStream` as desired
} catch (DbxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
答案 1 :(得分:0)
经过大量工具处理后,这里有些东西有效
String my_link = null;
URL my_url = null;
URLConnection conn = null;
BufferedReader reader = null;
try {
my_link = my_DbxClient.files().getTemporaryLink("/" + my_File).getLink();
my_url = new URL (my_link);
conn = my_url.openConnection();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} catch (DbxException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}