IO流12 --- 转换流InputStreamReader --- 技术搬运工(尚硅谷)
InputStreamReader 将字节输入流转换为字符输入流
@Test
public void test1(){
InputStreamReader isr = null;
try {
//字节输入流
FileInputStream fis = new FileInputStream("水浒传.txt");
//将字节输入流转换为字符输入流
isr = new InputStreamReader(fis);
char[] cbuf = new char[10];
int len;
while ((len = isr.read(cbuf)) != -1) {
String string = new String(cbuf, 0, len);
System.out.print(string);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(isr != null) {
try {
isr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}


浙公网安备 33010602011771号