現在、Android アプリケーション用に内部メモリにファイルを保存しようとしていますが、正しく保存できません!
ビットマップを保存する方法は次のとおりです。
private void storeBitmapInMemory(String id) throws IOException {
URL newurl = new URL(PictureUrl);
Bitmap bm = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
// The openfileOutput() method creates a file on the phone/internal storage in the context of your application
final FileOutputStream fos = context.openFileOutput(PREFIX + id +".jpeg", Context.MODE_PRIVATE);
// Use the compress method on the BitMap object to write image to the OutputStream
bm.compress(CompressFormat.JPEG, 100, fos);
}
このメソッドを実行するとすべて問題ないように見えますが、実際には何も保存されません... このメソッドでメモリからファイルを読み込もうとすると:
private Bitmap getStoredBitmapFromMemory(int idAvatar) {
File cacheDir = context.getCacheDir();
File f = new File(cacheDir, PREFIX + Integer.toString(idAvatar) + ".jpeg");
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return BitmapFactory.decodeStream(fis);
}
この例外をスローしています:
05-02 10:50:22.487: W/System.err(25805): java.io.FileNotFoundException: /data/data/com.example.xxxx/cache/AVATAR_400021371.jpeg: open failed: ENOENT (No such file or directory)
05-02 10:50:22.497: W/System.err(25805): at libcore.io.IoBridge.open(IoBridge.java:416)
05-02 10:50:22.497: W/System.err(25805): at java.io.FileInputStream.<init>(FileInputStream.java:78)
05-02 10:50:22.497: W/System.err(25805): at com.example.xxxx.Performer.getStoredBitmapFromMemory(Performer.java:140)
storeBitmapInMemory の何が問題になっていますか??