Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

Proper way to read file line by line?

Hi,

In java, what's the proper method to read a file, line by line? In my case, the data is human readable characters. It seems there are many different ways on the net. I guess I just want one large string representing the contents of the file.

Thanks
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

.readline() from BufferedReader.

BufferedReader reader = new BufferedReader(file);
 
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
   // process line
}

Open in new window

BufferedReader in  = new BufferedReader(new FileReader("somefile")); would be good.
ASKER CERTIFIED SOLUTION
Avatar of ysnky
ysnky
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial