---
title: "Java读取properties文件中文乱码问题的解决"
author: "minfirefox"
date: "2009-06-30T18:01:26Z"
tags: []
slug: "java-properties"
draft: false
lastmod: "2009-06-30T18:11:02Z"
id: 417795
url: "https://minfirefox.iteye.com/blog/417795"
---

Java直接读取properties文件时，中文会是乱码，这时可以用Java\jdk1.x.x\bin\<span style="color:red">native2ascii</span>.exe工具。
例如，把f1.properties转换成f2.properties。

在cmd的当前目录下输入

```cmd

native2ascii -encoding gbk f1.properties f2.properties
```

转换前f1.properties：

```properties

#编号=描述
cn=中国
```

转换后f2.properties：

```properties

#\u7f16\u53f7=\u63cf\u8ff0
cn=\u4e2d\u56fd
```


这样Java程序就可以正确识别中文了！

```java

	Properties prop=new Properties();      
	InputStream inputStream=new FileInputStream("E:\\f2.properties");      
	prop.load(inputStream);      
	String title=prop.getProperty("cn");   
	System.out.println(title);

```

转换前运行结果：
```控制台
???ú
```
转换后运行结果：
```控制台
中国
```