File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performing read/write to the file : how

 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, I believe we should be using the RandomAccessFile for it. Take a look at the tutorial available from Sun.

Cheers!
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic