读取properties文件中文问题

上一篇 / 下一篇  2014-01-22 15:27:46

今天帮一个客服的没纸做excel数据统计,因为需求复杂,excel满足不了,正巧这两天也没什么正事,就通过写代码帮她实现了。下午又没事做了,,就把代码封装下,打算以后操作更用户些。。
我把需要传入的数据,比如excel的路径啊,sheet的name啊等,写在le一个properties中,计划对这个文件进行操作。但我properties中有其他中文信息,,读取出来后是乱码,,搜索一阵解决办法后,最后搞定了。。。
先看看properties文件
 
excel_url=D:/TE/info.xls
sheet_name=info
goodinfo=选择多,有跟踪号,免邮,价格,网站简单,退款,质量,支付方式
gr=8
badinfo=质量,不良卖家,物流,实物,尺码表
br=5
 
java代码:
 
 
package com.ae.service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
public class Test {
 static String excel_url;
 static String sheet_name;
 static String goodinfo;
 static String gr;
 static String badinfo;
 static String br;
 static {
  InputStream is = Test.class.getClassLoader().getResourceAsStream(
    "info.properties");
  Properties pro = new Properties();
  try {
   InputStreamReader re = new InputStreamReader(is, "UTF-8");
   BufferedReader bf = new BufferedReader(re);
   pro.load(bf);
   excel_url = pro.getProperty("excel_url");
   sheet_name = pro.getProperty("sheet_name");
   goodinfo = pro.getProperty("goodinfo");
   gr = pro.getProperty("gr");
   badinfo = pro.getProperty("badinfo");
   br = pro.getProperty("br");
   System.out.println("excel_url:" + excel_url + "/sheet_name:"
     + sheet_name);
   System.out.println("goodinfo:" + goodinfo);
   System.out.println("badinfo:" + badinfo);
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
 public static void main(String[] args) {
  new Test();
 }
}
 
之前是直接pro.load(is)
后来做了编码,主要是
InputStreamReader re = new InputStreamReader(is, "UTF-8");
BufferedReader bf = new BufferedReader(re);
pro.load(bf);

TAG:

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 10623
  • 日志数: 7
  • 建立时间: 2013-11-07
  • 更新时间: 2014-04-17

RSS订阅

Open Toolbar