Skip to content

Instantly share code, notes, and snippets.

@madan712
Created January 10, 2013 13:45
Show Gist options
  • Save madan712/4502130 to your computer and use it in GitHub Desktop.
Save madan712/4502130 to your computer and use it in GitHub Desktop.
Java program to read a text file. Below java program can be used to read a text (.txt) file or any other text based file like .xml, .properties etc
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class ReadTextFile {
public static void main(String[] args) {
// Prove Text File to Read
String TextFileToRead = "c:/TextFile.txt";
try {
File file = new File(TextFileToRead);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String iterateEachLine = "";
while ((iterateEachLine = br.readLine()) != null) {
System.out.println(iterateEachLine);
}
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment