This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problems Adapting code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problems Adapting code" Watch "Problems Adapting code" New topic

Problems Adapting code

Lora Tully

Joined: Nov 29, 2004
Posts: 8
I wrote code last week for a program I am working on in my spare time. In the code I use an In file and OUT file. I now want to adapt it to instead read the IN file and output the data into an int array. COuld this be done as I think it would be hard to keep the order of byte in the write order etc...

while (i == 1)
if (first_byte == second_byte)
{// Decompression
first_byte = IN.readByte ();// Get repeat count
compressCount ++;

// Set up loop to print first_byte + 2 of second_byte
for (count = -1; count <= first_byte; count ++)
OUT.write (second_byte);
byteCount += 2 + first_byte;// increment output chars
first_byte = IN.readByte ();// get new first byte
compressCount ++;
} else{ // Not compressed
OUT.write (first_byte);
byteCount ++;
first_byte = second_byte; // Shift up chars
second_byte = IN.readByte (); // Read another
compressCount ++;
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
You can certainly write to a String and read from the String with StringWriter and StringReader, which support the usual I/O methods.
To put information into an int[] array and get the info back is easy to do, but not using the I/O methods.

You could look into the DataInputStream/DataOutputStream methods like readByte() and writeInt() which do I/O with primitives in a platform independent format.

Mike Gershman
SCJP 1.4, SCWCD in process
I agree. Here's the link:
subject: Problems Adapting code
It's not a secret anymore!