带编码表的读写

package com.heima.lei;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

public class Test4 {

    /**带编码表的读写 * @param args * @throws IOException */
    public static void main(String[] args) throws IOException {
        BufferedReader br = 
                new BufferedReader(new InputStreamReader(new FileInputStream("001.txt"),"GBK"));
        BufferedWriter bw = 
                new BufferedWriter(new OutputStreamWriter(new FileOutputStream("004.txt"),"UTF-8"));
        String line;
        while((line = br.readLine()) != null){
            bw.write(line);
            bw.newLine();
        }
        br.close();
        bw.close();
    }

}

你可能感兴趣的:(带编码表的读写)