我只是在嘗試使用此代碼編寫的文本文件:安卓:試圖保存文件
try {
File ins = new File(context.getFilesDir(), "myfile");
FileOutputStream out = new FileOutputStream(ins);
out.write(string.toString().getBytes());
out.close();
} catch (Exception e) {
e.printStackTrace();
}
我自己也嘗試這樣的代碼:
File aux = context.getFilesDir();
String filename = "myfile";
String string = "Hello world!";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(aux + filename, MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
問題:IM沒有得到任何錯誤,但是他們都沒有保存文件。我期望在找到新文件,因爲content.getFilesDir()
的輸出就是這樣。
而且,我無法找到根/data/
文件夾,但一個/Android/data
之一,而後者的裏面,有幾個目錄,如com.android.browser
或com.dropbox.android
,但他們沒有被命名爲com.example.tirengarfio.myapplication
。
您嘗試/ storage/emulated/data嗎?有時模擬不存在或可能事情正在存儲在SD卡中,但您的文件可能在裏面/存儲 –
你是如何驗證該文件不存在 – ligi