close
Android File Cache的特性就和Internal Storage一樣
一些內容可以參考[Android] 12-2 Internal Storage這篇
唯一不同的是當系統的Storage要滿的時候
會自動幫你把Cache內的檔案刪掉並且不會有任何提醒
1. 官網https://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage
2. 首先來看它的路徑Log.d("TAG", "file path = " + getCacheDir());
可以看到file path = /data/data/package名稱/cache
3. 知道位置後, 其它就和Java io一樣用了
其中可以用File.createTempFile(檔名, 副檔名) 來使用
try {
File file = File.createTempFile("TempFiile", ".test");
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write("Temp Content".getBytes());
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
4. 執行完程式後, 可以在cache資料夾內看到剛的檔案
5. 把檔案取出後則可以看到剛輸出的內容
文章標籤
全站熱搜