使用dropbox core api和android下载文本文件

时间:2015-12-04 10:32:02

标签: java android dropbox-api

我在下载文本文件时遇到问题。下载后我没有文件内容,下载的文件为空。 Android和Core Api

@Override
protected Boolean doInBackground(Void... params) {
    FileOutputStream outputStream = null;
    try {
        File fileDown = new File(LOCAL_PATH_DOWNLOAD);
        outputStream = new FileOutputStream(fileDown);//
        DropboxAPI.DropboxFileInfo info = mApi.getFile(DROPBOX_FILE_DIR_DOWNLOAD, null, outputStream, null);

        return false;
    } catch (Exception e) {
        System.out.println("Something went wrong: " + e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
            }
        }
    }
    return false;
}

我错了什么?谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

我使用上面的代码来执行此操作

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;