java读取properties配置文件时中文乱码解决办法

来源:互联网 发布:中国传统价值观 知乎 编辑:程序博客网 时间:2024/05/24 03:00

代码如下:

package com.test;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.util.Properties;public class ConProperty {private Properties pro;private InputStreamReader instream;public void init() throws IOException,FileNotFoundException{pro=new Properties();instream=new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("conf.properties"),"UTF-8");if(instream !=null){pro.load(instream);}else{throw new FileNotFoundException("property file not found in the classpath");}}public String getfirefox(){return pro.getProperty("firefox");}public String getsqlIP(){return pro.getProperty("sqlIP");}public String getdbname(){return pro.getProperty("dbname");}public String getsqluser(){return pro.getProperty("sqluser");}public String getsqlpass(){return pro.getProperty("sqlpass");}public String getresolutionPath(){return pro.getProperty("resolutionPath");}public String getdownloadsAbsoluteLocat(){return pro.getProperty("downloadsAbsoluteLocat");}public static void main(String[] args) {ConProperty conProperty=new ConProperty();try {conProperty.init();System.out.println(conProperty.getdownloadsAbsoluteLocat());} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}


0 0