【问题标题】:Reading a DropBox Text File读取 DropBox 文本文件
【发布时间】:2018-08-10 23:09:30
【问题描述】:

我有一个将图像和文本文件加载到 Dropbox 的 Android 应用程序。我已经弄清楚了身份验证和上传过程。

现在,使用同一个经过身份验证的会话,我想读取一个上传的文本文件(以查找更改)。我找到了一个下载示例,但这意味着将其写入本地 SD,然后在那里读取......根本没有效率(部分原因是需要额外的 android 权限)。

我检查了Dropbox's v2 documentation,似乎确实有一堆读取调用,但我终其一生都无法弄清楚如何使用它们。有用的Android-Dropbox examples 似乎也没有解决我的具体问题。我在 stackoverflow 上也找不到任何 v2 示例。

当然,有人可以指点我一个简单的例子,它提供了一个不错的 InputStream。

【问题讨论】:

标签: android dropbox-api


【解决方案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();
}

【讨论】:

    【解决方案2】:

    经过大量工具,这里有一些可行的方法

        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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      相关资源
      最近更新 更多