The Artima Developer Community
Sponsored Link

Java Answers Forum
random acesses from a file

2 replies on 1 page. Most recent reply: Feb 20, 2004 2:10 AM by Viswanatha Basavalingappa

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
maxima

Posts: 15
Nickname: maxima
Registered: Nov, 2003

random acesses from a file Posted: Jan 19, 2004 10:00 AM
Reply to this message Reply
Advertisement
i want to acesses randomly data from the text file and then i want to process that data and then i want to store that data in a different file in text format...can you tell me how can i do this???


do i have to use RandomAccessFile ?? stringTokenizer and BufferedReader??? ....but RandomAcessFile does operation in byte format...so processing of the data would be dificult, i feel.

thanks


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: random acesses from a file Posted: Feb 17, 2004 12:21 AM
Reply to this message Reply
YES, you can use
RandomAccessFile(File file, String "r") throws FileNotFoundException

Value
Meaning
File file
"file" which you would like to read .
mode
"r" Open for reading only. Invoking any of the write methods of the resulting object will cause an IOException to be thrown.

Then you can ready by lot of diffrent option..
look at.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html


Viswa
IBM
India
--------

Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: random acesses from a file Posted: Feb 20, 2004 2:10 AM
Reply to this message Reply
Here is the sample code for the same..

try {
File f = new File("filename");
RandomAccessFile raf = new RandomAccessFile(f, "rw");

// Read a character
char ch = raf.readChar();

// Seek to end of file
raf.seek(f.length());

// Append to the end
raf.writeChars("aString");
raf.close();
} catch (IOException e) {
}



I hope this helps you
Viswa
-------

Flat View: This topic has 2 replies on 1 page
Topic: How To Write A Code "Press Any Key to continue" Previous Topic   Next Topic Topic: Java Error Class

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use