Storing data in binary files

I am trying to store my data in binary files to save space and lessen time spent on hard disk reads. However, I can't seem to find the proper way to do this in java.

For example, I have the integer 65535 in java. How do I convert it into a 2 byte string FF FF in java?

When I read 2 bytes FF FF to a string from a binary file, how do I interpret it as a -32767 or a 65535 ?

Sorry if this seems like a really obvious question. None of the integer or string methods in java seems to do what I want :(

[524 byte] By [Big_Ducka] at [2007-11-26 12:44:46]
# 1
the java tutorial has a page on binary i/o http://java.sun.com/docs/books/tutorial/essential/io/datastreams.html
jsalonena at 2007-7-7 16:22:48 > top of Java-index,Java Essentials,New To Java...
# 2
If all you want is a compressed file, you might want to use java.util.zip.GZIPOutputStream, and send it data in a simple format (like XML) rather than trying to compress everything to bytes yourself.
paulcwa at 2007-7-7 16:22:48 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks, exactly what I'm looking for.
Big_Ducka at 2007-7-7 16:22:48 > top of Java-index,Java Essentials,New To Java...