文件的输入通过字符流(reader)
public class FileInputReader {
public static void main(String[] args) {
File file = new File("learn.txt");
try {
FileInputStream fis = new FileInputStream(file);
//把字节流转化成字符流
InputStreamReader fir = new InputStreamReader(fis);
char c [] = new char[1024];
int l = 0;
while ((l = fir.read(c)) != -1) {
System.out.println(new String(c,0,l));
}
fis.close();
fir.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文标题:文件的输入通过字符流(reader)
本文链接:https://www.haomeiwen.com/subject/wdldjftx.html
网友评论