读取文件
1.传统IO文件读取方式
package com.lyj.test2;
import java.io.*;
/**
* Created by LYJ on 2016/10/9.
* 传统读取文件的方式(按行读取)
*/
public class TestIO {
public static void main(String... args) {
String filePath="E:\\JAVA\\javaPrj\\TestNIOStream1\\resources\\qq.txt";
String encoding = "utf-8";
try {
File file = new File(filePath);
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
System.out.println(lineTxt + " --------- lineTxt --- TestIO.main\n");
}
read.close();
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
}catch (IOException e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
}
}
2.通过java NIO读