如何解决Android Dropbox API文件下载
| 我目前正在开发支持android dropbox api的android应用程序。我有它的工作,以便它从android SD卡发送文件到保管箱文件夹。然后,我以后需要能够下载该文件并将其再次保存到手机SD卡中。 我如何从Dropbox下载文件并将其保存到设备,关于android api的文档很少甚至没有。 感谢您的任何帮助,您可以提供。解决方法
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,read);
}
} finally {
//in finally block:
if (bw != null) {
bw.close();
}
if (br != null) {
br.close();
}
}
return true;
}
来源:http://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521
, 如果尝试此链接,请从Dropbox下载文件并将其保存到SDCARD中,这完全有助于通过Drop Box下载任何类型的文件
, private boolean downloadDropboxFile(String dbPath,read);
}
} finally {
//in finally block:
if (bw != null) {
bw.close();
}
if (br != null) {
br.close();
}
}
return true;
}
它将为您工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。