[英]Android Dropbox api file exists
我正在从Dropbox成功下载文件,但是现在我想检查Dropbox中的文件是否不存在。
似乎FileNotFoundException
无法正常工作,因此我添加了一个布尔值来进行检查,但没有成功。
你有什么建议吗?
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 {
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();
}
我使用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.