2012-07-15 38 views
0

我用這種方法在上傳Dropbox的文件:如何覆蓋保存在收存箱中的文件?

public void upload() { 

     FileInputStream inputStream = null; 
     try { 
      File file = new File(Environment.getExternalStorageDirectory() 
        .toString() + "/write.txt"); 
      inputStream = new FileInputStream(file); 
      Entry newEntry = mDBApi.putFile("/write.txt", inputStream, 
        file.length(), null, null); 
      Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev); 
     } catch (DropboxUnlinkedException e) { 
      // User has unlinked, ask them to link again here. 
      Log.e("DbExampleLog", "User has unlinked."); 
     } catch (DropboxException e) { 
      Log.e("DbExampleLog", "Something went wrong while uploading."); 
     } catch (FileNotFoundException e) { 
      Log.e("DbExampleLog", "File not found."); 
     } finally { 
      if (inputStream != null) { 
       try { 
        inputStream.close(); 
       } catch (IOException e) { 
       } 
      } 
     } 

    } 

但是當已經該文件的文件夾,則文件獲得改名寫的存在(1).txt文件 ,但我想,如果已經將文件存在於Dropbox共享文件夾中,那麼它將被替換。我現在應該怎麼做?

+0

沒有ü嘗試'file.exists()'函數 – reiley 2012-07-15 09:52:56

+0

沒有,但是如果這個工程,然後我應該怎麼做才能覆蓋以前的? – Reyjohn 2012-07-15 10:35:12

+0

任何人都可以幫忙嗎? – Reyjohn 2012-07-15 22:09:25

回答

1

可以使用mDBApi.putFileOverwrite代替mDBApi.putFile