我迷路了。我可以訪問我用USB創建的文件嗎
我透過這個(剝離)代碼文件:
File dir = getBaseContext().getDir(dirPath, MODE_WORLD_WRITEABLE);
try {
File file = new File(dir, fileName);
FileOutputStream fous = new FileOutputStream(file);
fous.write(data);
fous.flush();
fous.close();
long l = file.length();
Log.i("PpCameraActivity", "File size : " + l);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Error while trying to write photo file", Toast.LENGTH_LONG).show();
}
我可以用logcat的,我的文件似乎是創建驗證(它有一個不爲空lenght)。但是當我將我的android設備連接到我的電腦時,我看不到它。 那麼...我的文件在哪裏?它隱藏了嗎?擦掉了?
編輯:我現在想要的SD卡寫具體而言,使用此:
File root = Environment.getExternalStorageDirectory();
File jpegFile = new File(root.getAbsolutePath() + "/myApplication/" + filePath);
try {
jpegFile.mkdirs();
FileOutputStream fous = new FileOutputStream(jpegFile);
fous.write(data);
fous.flush();
fous.close();
Log.i("PpCameraActivity", "File written : " + jpegFile.getAbsolutePath());
Toast.makeText(getBaseContext(), "File written : " + jpegFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
long l = jpegFile.length();
Log.i("PpCameraActivity", "File size : " + l);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "Error while trying to write photo file", Toast.LENGTH_LONG).show();
}
,但我得到的FileOutputStream中創建一個FileNotFoundException異常...
'dirPath'包含什麼? – 2010-02-04 22:03:28
也許是我的新目錄不是在SD卡上創建的?如果是這樣,我該如何選擇在SD卡上創建一個目錄? – 2010-02-04 22:08:24
看來我應該可以在SDcard中使用 獲得的文件寫入文件的根= Environment.getExternalStorageDirectory() 但是,當我嘗試寫我得到一個FileNotFoundException ... – 2010-02-04 22:24:52