Skip to content

Instantly share code, notes, and snippets.

@quydm
Created June 17, 2017 06:12
Show Gist options
  • Save quydm/314cd429d917594f2cfad043fd16a150 to your computer and use it in GitHub Desktop.
Save quydm/314cd429d917594f2cfad043fd16a150 to your computer and use it in GitHub Desktop.
Read a text file line by line using Java
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class ReadFileLineByLine {
public static void readFile(String fileName) {
try {
BufferedReader br = new BufferedReader(new FileReader(fileName));
for (String line; (line = br.readLine()) != null; ) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment