ITeye博客

泰文保持不乱码

dmwdmc · 2011-01-28 01:49 · core JAVA jvm · 编程语言 · Markdown


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 的编码也保持一致。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。