Created
June 17, 2017 06:12
-
-
Save quydm/314cd429d917594f2cfad043fd16a150 to your computer and use it in GitHub Desktop.
Read a text file line by line using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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