2016-02-14 109 views
1

我正在從Dropbox成功下載文件,但現在我想檢查Dropbox中的文件是否不存在。
看來FileNotFoundException不起作用,所以我添加了一個布爾值來檢查這個,但沒有成功。
你有什麼建議嗎?Android Dropbox api文件存在

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); 
    } 
} 
+1

是它的工作原理,謝謝 – user2847219

回答

0

嘗試追趕只是一般例外:

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(); 
    } 
0

我用DbxException消息:

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