android – 从Dropbox下载文件并将其保存到SDCARD

我现在真的很沮丧..我想从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,read);
    }
} finally {
    //in finally block:
    if (bw != null) {
        bw.close();
    }
    if (br != null) {
        br.close();
    }
}

return true;

}

这里我在br = new BufferedInputStream line..Pls帮助中收到错误

解决方法

我找到了方法
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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...