17 转换流----字节转换为字符

package convertIO;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

/*
 * 转换流: 字节转为字符
 *     1. 输出流 OutputStreamWriter  编码
 *     2. 输入流 InputStreamReader   解码
 */
public class Convert3 {
    public static void main(String[] args) throws Exception {
        //指定解码字符集,此时2.txt的格式为utf-8
        BufferedReader br = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream(
                                new File("E:/jar/a/2.txt")),"utf-8")
                );
        
        String info;
        while((info = br.readLine()) != null){
            System.out.println(info);
        }
        br.close();
    }
}

你可能感兴趣的:(17 转换流----字节转换为字符)