簡體   English   中英

android-dropbox api-如何查找和上傳文件

[英]android - dropbox api - how to find and upload a file

我正在使用Dropbox API,我想在Dropbox上上傳文件。 在保管箱中將有一個名稱相同的文件需要覆蓋。

我嘗試使用此代碼來找到文件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);

但我一直在找不到文件異常。 誰能告訴我我在做什么錯?

您實際上可能需要為應用程序指定緩存路徑,以確保文件位於您可以訪問的位置,即:基於此設置文件名:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM