2012-07-15 73 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