Java读取txt

2016-11-01  邓智群 

public static void main(String[]args){
try{
File file = new File("\\data\\test.txt");
if(file.isFile()&&file.exists()){
String encoding="";
InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);
BufferedReader bufferreader = new BufferedReader(read);
String linText = null;
while((linText = bufferreader.readLine())!=null){
System.out.println(linText);

}

read.close();


}
else{
System.out.println("找不到系统文件");
}
}catch(Exception e){
e.printStackTrace();
}
}



获得文件句柄,把输入流转换成字节流,然后readline输出


364°/3641 人阅读/0 条评论 发表评论

登录 后发表评论