• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading file

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
grapes are vegan food pellets. Eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic