定义Java类实现字节流转字符流
package com.buaa.comparable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
public class TestRead {
	
	/*static void parse(char[] c,String str){
		str = str.copyValueOf(c);
		try {
			str = new String(str.getBytes("gbk"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}*/
	public static void main(String[] args) {
		testReader();
	}
	static void testReader(){
		File f = new File("d:/a.txt");
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(f);
			InputStreamReader isr = new InputStreamReader(fis,"utf-8");
			int temp = 0;
		while((temp=isr.read())!=-1){
			char c = (char) temp;
			
			System.out.print(c);
		  }
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
				try {
					if (fis!=null) {
					fis.close();
				  }
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号