public class ReadLineDemo {
private void readDemo(){
try {
//创建缓存流对象
BufferedReader fis = new BufferedReader(new FileReader("c:\\puke\\test.txt"));
//用于获取文本
String line = null;
try {
//读行行,如果返回null
while((line=fis.readLine())!=null){
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//读完关闭流
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new ReadLineDemo().readDemo();
}
}
|
|