gpt4 book ai didi

android - 从 Dropbox 下载文件并保存到 SDCARD

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:18:58 24 4
gpt4 key购买 nike

我现在真的很沮丧..我想从 Dropbox 下载一个文件并将该文件保存到 SDCARD..我得到的代码是:

     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;

这里我在 br=new BufferedInputStream 行上遇到错误..请帮忙

最佳答案

我找到了方法:

      File file= new File("/sdcard/New_csv_file.csv");
OutputStream out= null;
boolean result=false;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
DropboxFileInfo info = mApi.getFile("/photos/New_csv_file.csv", null, out, null);
Log.i("DbExampleLog", "The file's rev is: " + info.getMetadata().rev);
Intent JumpToParseCSV=new Intent(context,ParseCSV.class);
JumpToParseCSV.putExtra("FileName", file.getAbsolutePath());
Log.i("path", "FileName"+ file.getAbsolutePath());
((Activity) context).finish();
context.startActivity(JumpToParseCSV);
result=true;
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while downloading.");
file.delete();
result=false;
}


return result;

谢谢大家....

关于android - 从 Dropbox 下载文件并保存到 SDCARD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9566884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com