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

android – 从Dropbox下载文件并将其保存到SDCARD,第1张

概述我现在真的很沮丧..我想从Dropbox下载文件并将该文件保存到SDCARD ..我得到的代码为: private boolean downloadDropboxFile(String dbPath, File localFile) throws IOException{BufferedInputStream br = null;BufferedOutputStream bw = null; 我现在真的很沮丧..我想从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 – 从Dropbox下载文件并将其保存到SDCARD全部内容,希望文章能够帮你解决android – 从Dropbox下载文件并将其保存到SDCARD所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1136256.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存