Use BufferedReader to read a file
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class BufferedReaderTest {
public static void main(String[] args) throws Exception{
String fileName = "c:\\tmp\\test.txt";
File file = new File(fileName);
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line = "";
while ((line = br.readLine())!=null){
System.out.println("line="+line);
}
br.close();
fr.close();
}
}
No comments:
Post a Comment