---
title: "泰文保持不乱码"
author: "dmwdmc"
date: "2011-01-28T01:49:56Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-01-28T01:49:56Z"
id: 898617
url: "https://dmwdmc.iteye.com/blog/898617"
---

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