| Author |
Performing read/write to the file : how
|
Aruneesh Salhotra
Ranch Hand
Joined: May 12, 2004
Posts: 167
|
|
Hi, I wanted to know what is the recommended way to read/write text from the file. I see the instructions say numeric data is read/written as DataInputStream while text data is read/stored contain only 8 bit character. Should I be using RandomAccessFile or something else. What is the recommended way of performing this. Regards Aruneesh
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
Yep, I believe we should be using the RandomAccessFile for it. Take a look at the tutorial available from Sun. Cheers!
|
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
|
 |
Aruneesh Salhotra
Ranch Hand
Joined: May 12, 2004
Posts: 167
|
|
I am not sure how the files should be stored as. After the header, should the data be stored as plain text. Java uses UTF-16 as default encoding, and on opening the file when generated using UTF-16, it is comes like boxes/chars. I am trying to use US-ASCII to write to the file, but the generate file doesnt seem to contain plain text. I am using RandomAccessFile. Here is like a sample code, I am writing. Please help raf.seek(length); raf.writeChars(new String(lr.location.getBytes("US-ASCII"),"US-ASCII")); raf.writeInt(lr.size); raf.writeChars(new String(lr.rate.getBytes(),"US-ASCII")); raf.writeChars(new String(lr.smoking.getBytes(),"US-ASCII")); raf.writeChars(new String(lr.date.getBytes(),"US-ASCII")); raf.writeChars(new String(lr.owner.getBytes(),"US-ASCII"));
|
 |
 |
|
|
subject: Performing read/write to the file : how
|
|
|