|
Read Text File
The following example shows how to read a text file using BufferedReader.
|
package com.bethecoder.tutorials.io;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadTextFile {
/**
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\abc.txt"));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
| |
It gives the following output,
Hello World
WriteTextFile Example
|
|