2012-08-06 97 views
0

我使用dropbox API,並且我想上傳一個Dropbox上的文件。 Dropbox中會有一個文件需要被覆蓋。android - dropbox api - 如何查找和上傳文件

我試過這段代碼找到文件profiles.txt,然後上傳它,但我總是找不到文件。

// create the file 
FileOutputStream file = openFileOutput("profiles.txt", MODE_WORLD_READABLE); 
// download the contents from the online file into the newly created file 
DropboxFileInfo info = mDBApi.getFile("/profiles.txt", null, file, null); 
// close the file 
file.flush(); 
file.close(); 

// read the file 
FileInputStream fstream = openFileInput("profiles.txt"); 
InputStreamReader isr = new InputStreamReader(fstream); 
char[] inputBuffer = new char[7]; 
isr.read(inputBuffer); 
String readString = (new String(inputBuffer)).trim(); 
int id = Integer.parseInt(readString); 

// record your id 
SharedPreferences mySharedPreferences = getSharedPreferences("User_info_file", MODE_PRIVATE); 
SharedPreferences.Editor editor = mySharedPreferences.edit(); 
editor.putString("TEXT_ID_KEY", readString); 
editor.commit(); 

// create the new file with the new id 
file = openFileOutput("profiles.txt", MODE_WORLD_READABLE); 
OutputStreamWriter osw = new OutputStreamWriter(file); 
osw.write(String.format("%d", id+1)); 
osw.flush(); 
osw.close(); 

File file2 = new File("profiles.txt"); 
String ab_path = (Tab_User_InfoActivity.this).getCacheDir().getAbsolutePath() + File.separator + "profiles.txt"; 
FileInputStream inputStream = new FileInputStream(ab_path); // CRASH HERE 
Entry newEntry = mDBApi.putFile("profiles.txt", inputStream, file2.length(), null, null); 

但我總是收到文件未找到異常。誰能告訴我我做錯了什麼?

+0

哪個呼叫正在生成例外? – 2012-08-06 21:03:11

+0

FileInputStream inputStream = new FileInputStream(ab_path); – omega 2012-08-06 21:11:34

+0

你能打印ab_path嗎? – 2012-08-06 21:18:29

回答

0

你實際上可能需要指定您的應用程序,以確保該文件是在你有機會獲得,即一個位置緩存路徑:建立在此基礎上的文件名:

context.getCacheDir().getAbsolutePath() + File.separator + "profiles.txt" 
+0

這個,沒有用。我用我更多的代碼更新了我的第一篇文章。這有幫助嗎? – omega 2012-08-06 21:58:28