问题描述
|
我目前正在开发支持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;
}
它将为您工作。