代码之家  ›  专栏  ›  技术社区  ›  RudyF

读取DropBox文本文件

  •  0
  • RudyF  · 技术社区  · 8 年前

    我有一个android应用程序,可以将图像和文本文件加载到Dropbox中。我已经知道了身份验证和上传过程。

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

    我检查过了 Dropbox's v2 documentation 似乎有很多读电话,但我一生都不知道如何使用它们。有用的 Android-Dropbox examples 似乎也没有解决我的具体问题。我也找不到stackoverflow上的任何v2示例。

    当然,有人可以给我举一个简单的例子,它提供了一个很好的输入流。

    2 回复  |  直到 8 年前
        1
  •  1
  •   Greg    8 年前

    你可以用 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
  •  0
  •   RudyF    8 年前

    经过大量的加工,这里有一些东西是有效的

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