Android的Dropbox的API文件下载文件、Android、Dropbox、API

2023-09-06 01:29:02 作者:缺锌缺钙缺你爱

我目前工作在Android应用程序,是支持Android的Dropbox API。我已完成了工作,所以它发送从Android SD卡收存箱文件夹中的文件。我再后来就需要能够下载这个文件,并保存到手机的SD卡了。

我如何可以从Dropbox的文件并将其保存到设备中,很少有没有对Android的API文档。

感谢您的帮助,您可以提供。

解决方案

 私人布尔downloadDropboxFile(字符串DBPATH,文件localFile)抛出IOException异常{

    的BufferedInputStream BR = NULL;
    的BufferedOutputStream体重= NULL;

    尝试 {
        如果(!localFile.exists()){
            localFile.createNewFile(); //否则Dropbox的客户端将无法默默地
        }

        FileDownload FD = api.getFileStream(Dropbox的,DBPATH,NULL);
        BR =新的BufferedInputStream(fd.is);
        体重=新的BufferedOutputStream(新的FileOutputStream(localFile));

        byte []的缓冲区=新的字节[4096];
        INT读取;
        而(真){
        读= br.read(缓冲区);
        如果(读< = 0){
        打破;
        }
        bw.write(缓冲,0,读);
        }
    } 最后 {
        //在finally块:
        如果(BW!= NULL){
            bw.close();
        }
        如果(BR!= NULL){
            br.close();
        }
    }

    返回true;
}
 

来源: HTTP://forums.dropbox。 COM / topic.php ID = 23189&放大器;?回答= 5#后159521

I am currently working on an android app that is to support the android dropbox api. I have got it working so that it sends a file from the android sd card to a dropbox folder. I then later on need to be able to download this file and save it to the phone sd card again.

android开发的中文api文档怎么下载

How can I download the file from Dropbox and save it to the device, there is very little to no documentation about the android api.

Thanks for any help you can provide.

解决方案

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

Source: http://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521