wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Reading in a File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading in a File" Watch "Reading in a File" New topic
Author

Reading in a File

Jax Laakso
Greenhorn

Joined: Dec 07, 2001
Posts: 23
I can't seem to remember how to read in a .txt file into a java program. Help?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading in a File
 
Similar Threads
WA #1.....word association
java io
Creating a file by giving relative path
performance issues with file read and write
Struts FormFile (parsing .csv files)