简体   繁体   English

Android Dropbox api文件存在

[英]Android Dropbox api file exists

I'm downloading a file from Dropbox successfully, but now I want to check if the file in Dropbox does not exist. 我正在从Dropbox成功下载文件,但是现在我想检查Dropbox中的文件是否不存在。
It seems that the FileNotFoundException does not work, so I added a boolean to check this, but without success. 似乎FileNotFoundException无法正常工作,因此我添加了一个布尔值来进行检查,但没有成功。
Do you have any advice? 你有什么建议吗?

 protected class DownloadDB extends AsyncTask<Context, Integer, String> {
    ProgressDialog myLoadingDialog;
    boolean exists = true;
     @Override
    protected void onPreExecute() {
        myLoadingDialog = new ProgressDialog(Impostazioni_pro.this);
        myLoadingDialog.setMessage(getString(R.string.sinc));
        myLoadingDialog.setIndeterminate(false);
        myLoadingDialog.setCancelable(false);
        myLoadingDialog.show();
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(Context... arg0) {

        try {
            File OutFolder = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name) + "/sync/psw.crypt");
            OutputStream out = new FileOutputStream(OutFolder);
            mApi.getFile("/myfile.db", null, out, null);
        } catch (FileNotFoundException e) {
            exists = false;
            e.printStackTrace();
         } catch (DropboxException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        myLoadingDialog.dismiss();
            if(exists){

                importaDB();
            }
        super.onPostExecute(result);
    }
}

Try catching just the generic Exception: 尝试仅捕获通用异常:

    try {
        File OutFolder = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name) + "/sync/psw.crypt");
        OutputStream out = new FileOutputStream(OutFolder);
        mApi.getFile("/myfile.db", null, out, null);
    } catch (Exception e) {
        exists = false;
        e.printStackTrace();
    }

I use DbxException message: 我使用DbxException消息:

try{
    OutputStream outputStream = new FileOutputStream(dbPath);
    client.files.downloadBuilder("/"+backupFileName).run(outputStream);
} catch (DbxException e) {
    if (e.getMessage().contains("not_found")) exists= false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM