Re: Question on binary files
Tom A. wrote:
I'm an old Pascal programmer who is trying to revitalize my
programming skills. My first project is an old mainframe game. In
the program there was a rather large data structure which we packed
into (iirc) 10 60 bit words (with only 2 bits that I have found to
buffer it out. We cared about memory space back then :-)
In Pascal, it was easy to write this thing out to a file :
write(datastructure) and all 10 words (100 or so fields), were
written out.
In Java, I created a class to hold the record. I will not be packing
it -- if a field only goes from 0 to 7 I'm not going to be packaging
it with fields to fill up the whole byte.
But I was wondering how Java programs do this sort of thing. I'm sure
I _could_ pack up the structure, and I'm sure there are many ways to
do it, but I was wondering if there is a preferred way, or an easier
way.
There are several possibilities. Perhaps the most basic,
data-focused as opposed to object-focused approach would be to
use java.io.DataOutputStream and java.io.DataInputStream.
--
Eric.Sosman@sun.com