从Dropbox Android sdk下载整个文件夹

时间:2014-04-02 06:46:26

标签: android dropbox dropbox-api

我正在我的Android sdk中集成dropbox来从dropbox下载所有文件, 我可以从每个文件夹下载所有文件,但现在我需要从dropbox的特定路径下载整个文件夹。

我试过

    DropboxFileInfo info = mApi.getFile(path + FileName,null, out, null);

Google Play商店中已有的一个应用程序,可以下载dropbox文件和文件夹link

我已经提到了 this

但无法下载整个文件夹 请指导我

1 个答案:

答案 0 :(得分:0)

按照官方Dropbox API指南Here

进行操作
private boolean downloadDropboxFile(String dbPath, File localFile) throws IOException{

BufferedInputStream br = null;
BufferedOutputStream bw = null;

try {
    if (!localFile.exists()) {
        localFile.createNewFile(); //otherwise dropbox client will fail silently
    }

    FileDownload fd = api.getFileStream("dropbox", dbPath, null);
    br = new BufferedInputStream(fd.is);
    bw = new BufferedOutputStream(new FileOutputStream(localFile));

    byte[] buffer = new byte[4096];
    int read;
    while (true) {
    read = br.read(buffer);
    if (read <= 0) {
    break;
    }
    bw.write(buffer, 0, read);
    }
} finally {
    //in finally block:
    if (bw != null) {
        bw.close();
    }
    if (br != null) {
        br.close();
    }
}

return true;

}

以下是来源:https://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521