Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading in a File  RSS feed

 
Jax Laakso
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't seem to remember how to read in a .txt file into a java program. Help?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by reading a file into a java program. If you just want your java program to read a text file...
wrap a buffered reader around a file reader, and then use it's reaadline method to read one line at a time.
FileReader fr = new FileReader("Youfilename")
BufferedReader br = new Bufferedreader(fr)
String line = be.readLine()
while(line != null)
do whatever...
//read the next lien
line = be.readLine()

------------------
Bosun
SCJP for the Java� 2 Platform
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!