0

I am having a problem in the following conversion. The file becomes scrambled and loses all its info.

here is the method I am using to convert:

private byte[] readFileToArray(Object object) throws IOException{

    ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream(); 
      ObjectOutputStream objectOutput = new ObjectOutputStream(byteArrayOutput); 

      objectOutput.writeObject(object);
      objectOutput.flush(); 
      objectOutput.close(); 
      byteArrayOutput.close();

      byte [] data = byteArrayOutput.toByteArray();

      return data;
}

what should I do so that i don't lose the info in the files?

super-qua
  • 3,148
  • 1
  • 23
  • 30
fmag
  • 129
  • 1
  • 7
  • Please, could you post a more complete example? Your code is correct at first sight, so maybe your problem is with whatever you are feeding it with (what is the `object` variable?) – Jorge_B Mar 17 '14 at 13:57
  • I think the answer can be found here: http://stackoverflow.com/questions/2836646/java-serializable-object-to-byte-array – Dan K. Mar 17 '14 at 13:58

0 Answers0