Search code examples
androidfilestreamandroid-file

Why don't I get the updated file after writing to FileOutputStream?


This is perhaps a very naive question, but I cannot figure it out. After writing to a file with FileOutputStream, I read the file again to get updated content, but only get the original content:

File avatarFile = new File(avatarFilePath);
if(avatarFile!=null){
    if(!avatarFile.exists())
            avatarFile.createNewFile();             
    fos = new FileOutputStream(avatarFile);
}
boolean result = scaledBitmap.compress(Bitmap.CompressFormat.JPEG,Constants.COMPRESSED_AVATAR_QUALITY, fos);            
fos.flush();
fos.close();
//Now read again, but get the old avatar
File newfile = new File(avatarFilePath);
Picasso.with(context).load(newfile).into(imageView); 

What is happening here?


Solution

  • Picasso is using the old cached image.

    To bypass the memory cache, use following:

        Picasso.with(context).load(newfile).skipMemoryCache().into(imageView);