本例是緩存到本地sd卡指定目錄abcd文件夾下。
File file = new File("/sdcard/abcd");
if (!file.exists())
file.mkdir();
String newFilePath = "/sdcard/abcd"+"/" + fileName;
file = new File(newFilePath);
file.createNewFile();
b = new FileOutputStream(file);
FileOutputStream b = new FileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, b);// 把數據寫入文件
在這裏提一個緩存目錄API:getExternalFilesDir(null)
該API的好處是:當你寫在應用app的時候,該目錄也會一併刪除。