JAVA读取带中文参数的properties文件

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Test {
	private static Properties properties = new Properties();

	public static void main(String[] args) {
		try {
			InputStream is = Test.class.getClassLoader().getResourceAsStream("jdbc.properties");
			properties.load(is);
			String size = properties.getProperty("jdbc.password");
			System.out.println("----" + size);
			String name =new String(properties.getProperty("jdbc.password").getBytes("ISO8859-1"),"UTF-8");
			System.out.println("----"+name);
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
		}
	}
}

    properties文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/test
jdbc.username=root
jdbc.password=哈哈
 

你可能感兴趣的:(java)