Created
January 10, 2013 13:45
-
-
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
This file contains hidden or 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.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