Java 读取配置文件中的信息 中文乱码

来源:互联网 发布:sql server安装 编辑:程序博客网 时间:2024/06/10 09:41

1.java在读取配置文件的信息是出现中文乱码

解决方法如下函数
package BugFreeMailServer;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.Properties;  /** * Properties configure * @author Yi.Liu * @time  2016-7-22 */public class PropertiesUtil{       /**      *       * {读取磁盘上的properties配置文件}<br>      * 返回的市Properties的对象      * @param propertiesFilePath      * @return      */      public static Properties readFromSystemFile(String propertiesFilePath)      {          InputStream is = null;          BufferedReader bf = null;        Properties properties = null;          try          {              is = new FileInputStream(propertiesFilePath);              //这个要看你dd.properties文件的编码格式,如果编码格式是gbk的要用gbk的InputStreamReader读取,如果utf8的就不用特殊设置了,如果你手工输入的dd的信息应该是gbk的编码            bf = new BufferedReader(new InputStreamReader(is, "gbk"));            properties = new Properties();              properties.load(bf);          }          catch (FileNotFoundException e)          {              System.out.println("没有找到文件");              e.printStackTrace();          }          catch (IOException e)          {              System.out.println("读取properties文件失败");              e.printStackTrace();          }          finally  //关闭开启的资源        {              if (is != null)              {                  try                  {                      bf.close();                      is.close();                }                  catch (IOException e)                  {                      // TODO Auto-generated catch block                      e.printStackTrace();                  }              }          }          return properties;      }  }  
0 0
原创粉丝点击