This discussion is archived
2 Replies Latest reply: Oct 5, 2011 4:30 PM by 891631 RSS

Converting a file in an array of bytes and viceversa.

891631 Newbie
Currently Being Moderated
Hello everyone.
I'm a new member of the forum (not gonna use this thread to introduce myself, i think there should be a section to do that) and kind of a newbie in java.
As the title says, i need a way to convert a file (that exists somewhere in the filesystem) to an array of bytes (or a list of arrays of bytes if necessary) and a way to do the opposite (transforming the array of bytes, or the list of arrays, in the original file).
Basically, the code would be something like this:


+class MyClass{+
byte[] bytes;

+byte[] toBytes(aFile){...}+
+File toFile(byte[] bytes){...}+

How can i implement the toBytes() and the toFile() method?

Thanks in advance for your help.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points