0
我想寫或將我的檔案在Android的內部存儲和我這樣做 -寫入文件的內部存儲
try {
File file = new File("/data/local/measurement.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content.toString());
bw.close();
Log.d("hi", "WRITTEN");
} catch (IOException e) {
e.printStackTrace();
}
我已經measurement.txt在/數據/本地路徑,但沒有被寫入到它。我使用模擬器,我也給了權限像
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
不是你的問題,但你知道你可以做'新的FileWriter(文件)'。無論如何,你確定'content.toString()'返回一個非空字符串嗎?記錄其值以確認。 –
是的內容是一個Arraylist與其中的一些對象數據 – FAZ
您的日誌消息出現? –