Java IO流 之 InputStreamReader 字节流转字符流

http://www.verejava.com/?id=16994667084611

package com.io;

import java.io.*;

public class TestInputStreamReader
{
	public static void main(String[] args)
	{
		InputStream is=null;
		try
		{
			 is=new FileInputStream("res/chinese.txt");
			 //将inputStream 转换成 Reader
			 Reader reader=new InputStreamReader(is);
			 int l;
			 while((l=reader.read())!=-1)
			 {
				 System.out.println((char)l);
			 }
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				is.close();
			}
			catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}


http://www.verejava.com/?id=16994667084611

posted @ 2018-06-26 07:51  verejava  阅读(586)  评论(0编辑  收藏  举报