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();
			}
		}
	}
}

  

 

posted @ 2019-10-23 17:58  地中有山  阅读(136)  评论(0编辑  收藏  举报