Sample of reading from text file

E

Eitan M

Hello,

I need a code-sample for reading data from a text file
(including exceptions whether there is need to, and check end-of-file
communication).
(FileReader ?)

Thanks :)
 
E

Eitan M

....
Also,
How can I read a whole one line (I didn't find readln() or something) ?

Thanks :)
 
I

IchBin

Eitan said:
Hello,

I need a code-sample for reading data from a text file
(including exceptions whether there is need to, and check end-of-file
communication).
(FileReader ?)

Thanks :)
I replied to post in the other newsgroup you posted to.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
C

charles hottel

Eitan M said:
...
Also,
How can I read a whole one line (I didn't find readln() or something) ?

Thanks :)

import java.io.*;
public class FileTest{
public static void main(String[] args){
try{
File data = new File("grades.txt");
if (data.exists()){
BufferedReader in = new BufferedReader(
new FileReader(data));
String line = in.readLine();
while(line != null){
System.out.println(line);
line = in.readLine();
}
in.close();
}
else
System.out.println("The grades.txt file doesn't exist");
}
catch(IOException e){
System.out.println("An IOException has occurred.");
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top