• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading file  RSS feed

 
Kaby Khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I read a character file I mean line by line .. and then print it on the screen , all the lines I mean...
please do tell
thanks
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will work:
<pre>
import java.io.*;
public class Line {
public static void main(String[] args){
try {
BufferedReader reader = new BufferedReader(new FileReader(new File("/somepath/Line.java")));

String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}

reader.close();

} catch(Exception ex){
System.out.println(ex);
}
}

}
</pre>
------------------
Chris Stehno (Sun Certified Programmer for the Java 2 Platform)
[This message has been edited by Chris Stehno (edited August 24, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!