1.FileReader不能一行行读
FileReader fr = null;
try {
fr = new FileReader(new File(path));
StringBuffer stringBuffer = new StringBuffer();
int ch;
while ((ch = fr.read()) != -1) {
stringBuffer.append(ch);
}
System.out.println(stringBuffer);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(fr);//关闭流
}
2.BufferedReader可以一行行地读
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(new File(path)));
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
stringBuffer.append(line);
}
System.out.println(stringBuffer);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(br);//关闭流
}