0

I have a class which write a png in the internal storage. When I write and read it just after that, it works.

FileOutputStream fileOutStream = openFileOutput(filepath, Context.MODE_PRIVATE); mBitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutStream); fileOutStream.close(); 

(the type of Bitmap is a Bitmap)

FileInputStream fileInStream = openFileInput(filepath); byte[] fileContent = org.apache.commons.io.IOUtils.toByteArray(fileInStream); 

When I use the same read function, with the same filepath parameter (I verify id), but in another class, it doesn't work.

Is there a limitation when using with another class of the same project ?

Regards

5
  • Its not because you didn't flush the fileOutStream with fileOutStream.flush(); before closing it? Commented Jan 26, 2012 at 9:58
  • i tryied to flush it before but i removed it between my different try. it's very strange to read it the first time but not the second ... Commented Jan 26, 2012 at 10:04
  • Did you close fileInStream after first reading ? Commented Jan 26, 2012 at 10:15
  • Where exactly do you store your file? - In some kind of temp directory ('/tmp',...)? Commented Jan 26, 2012 at 10:18
  • i store signature of the users which are sync to a web service. I musn't loose them. Mohammed it was simply just that, can you post an answer and I'll mark you. Thank you Commented Jan 26, 2012 at 10:34

1 Answer 1

1

Are you sure there is only one underlying stream on this file? because if you have multiple stream and call close() method, this will enforce to close all other streams.. so correct implementation is to close the last stream or apply flush to each one .. and close the last .. btw: for a single process of stream writing there is no need to explicitly call flush() method, because close() methods will call it implicitly.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.