file i/o with byte values

K

kvnsmnsn

The only way I know how to do I/O with a file is with the
<println> and <readLine> methods. But now I'm getting ready to do a
project that will essentially have me writing binary to a file and
then reading binary from that file. The values written to and read
from will be <byte> values. Does anyone out there know how to just
plain write an individual <byte> to a file and read an individual
<byte> from one? Thanks in advance for any information you can give
me.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
L

Lee Fesperman

The only way I know how to do I/O with a file is with the
<println> and <readLine> methods. But now I'm getting ready to do a
project that will essentially have me writing binary to a file and
then reading binary from that file. The values written to and read
from will be <byte> values. Does anyone out there know how to just
plain write an individual <byte> to a file and read an individual
<byte> from one? Thanks in advance for any information you can give
me.

Do a little reading in the java.io package. InputStream and OutputStream are the basic
classes for accessing byte values in a stream. They provide read() and write() for
bytes. For files, you'd use FileInputStream and FileOutputStream. For random access, see
RandomAccessFile.
 
K

kvnsmnsn

Lee Fesperman posted:

=> The only way I know how to do I/O with a file is with the
=> <println> and <readLine> methods. But now I'm getting ready to do a
=> project that will essentially have me writing binary to a file and
=> then reading binary from that file. The values written to and read
=> from will be <byte> values. Does anyone out there know how to just
=> plain write an individual <byte> to a file and read an individual
=> <byte> from one? Thanks in advance for any information you can give
=> me.
=
=Do a little reading in the java.io package. InputStream and
=OutputStream are the basic classes for accessing byte values in a
=stream. They provide read() and write() for bytes. For files, you'd
=use FileInputStream and FileOutputStream. For random access, see
=RandomAccessFile.

Thanks! <FileInputStream> and <FileOutputStream> did exactly
what I needed.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top