java 实现文本格式转换
代码如下,不太规范,仅作学习用
import java.io.*;
public class CharSetTest {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(new FileInputStream("F:\\test\\in.txt"),"GBK");//读入格式必须正确
BufferedReader bfr = new BufferedReader(isr);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\test\\out.txt"),"UTF-8");//写入格式可以更改为别的也不会出现乱码
String str;
while((str = bfr.readLine())!=null) {//读出来的经过转码后的字符
osw.write(str+"\r\n"); //写入时会自动根据字符查找转换后的格式的相应编码
//osw.flush();
}
bfr.close();
osw.close();
}
}