dmwdmc 发表于 2013-1-15 02:10:37

泰文保持不乱码

public class Test1 {public static void main(String[] args) throws IOException {InputStream fi=new FileInputStream("1.txt");Reader ir=new InputStreamReader(fi,"UTF-8");OutputStream os=new FileOutputStream("2.txt",true);Writer ow=new OutputStreamWriter(os,"UTF-8");BufferedReader in=new BufferedReader(ir);PrintWriter out=new PrintWriter(ow);String str;while((str=in.readLine())!=null){out.println(str);}in.close();out.close();}}
然后在1.txt中写入泰国文字。
运行程序。2.txt就能得到泰国文字。

要注意的是:
1。在1.txt中的泰国文字读到程序中,在eclipse 中打印出的很是是乱码,可能是因为eclipse本身如果不加特别设置会不支持泰国文字。
但是读到程序中后直接写人2.txt就是保持泰文了。
2。1.txt. 和2.txt的编码都要是程序中的编码,例如utf-8.
最好和eclipse 的编码也保持一致。
页: [1]
查看完整版本: 泰文保持不乱码