| Author |
Problems Adapting code
|
Lora Tully
Greenhorn
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
|
 |
 |
|
|
subject: Problems Adapting code
|
|
|