这份代码在别人的机子上能运行,但在我的机子上却报错了,请大家帮帮忙,看看是什么问题。以下是报错信息:(主要就是properties.load()的问题,说不支持reader)
Exception sending context initialized event to listener instance of class com.fortune.hms.core.web.listener.StartupListener
java.lang.Error: Unresolved compilation problem: 
The method load(InputStream) in the type Properties is not applicable for the arguments (Reader)

以下是本人代码:
try {
FileInputStream fis = new FileInputStream(filePath
+ "/config.properties");
Reader r = new InputStreamReader(fis, "UTF-8");//................................... 这里报错 ..........................................
props.load(r);
//....................................................................................... Iterator it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
logger.info("config.properties key:" + key);
configMap.put(key, props.get(key));
}
} catch (Exception ex) {
logger.error(ex.getMessage());
}

解决方案 »

  1.   


    java.io.InputStream is = PropertyUtil.class
    .getResourceAsStream(propertyFilePath);
    if (is == null) {
    return loadPropertyFileByFileSystem(propertyFilePath);
    }
    Properties ppts = new Properties();
    try {
    ppts.load(is);
    return ppts;
    } catch (Exception e) {
    _log.debug("加载属性文件出错:" + propertyFilePath, e);
    return null;
    }这样试试
      

  2.   

    呵呵,看jdk的api就知道那个load方法的参数了别人机器上是不是重载了那个方法啊
      

  3.   

     java.util.Properties的load方法声明形式为:void load(InputStream inStream) 从输入流中读取属性列表(键和元素对)。这里参数为字节输入流,而Reader为字符输入流,并且两者没有继承关系,所以你的程序会报错
      

  4.   

    The method load(InputStream)  props.load(r);参数类型不对啊
      

  5.   

    这个load方法有重载的 是可以传入Reader对象的
    具体楼主还是跟踪下吧
      

  6.   

    这也暗示了 Propperties 文件是用来配置参数的,而且都是 ASCII 码,在里面写汉字是不推荐的,如果没有汉字,那用 InputStream 就足够了,不需要考虑字符集的。
      

  7.   

    比较同意楼上提到的jdk问题,你的编译环境可能不支持那个Reader型参数的重载方法,而别人的支持,查下这个java.lang.Error: Unresolved compilation problem:
    The method load(InputStream) in the type Properties is not applicable for the arguments (Reader)而再上面发送事件给监听者有异常,可能就是因这个错误引起的事件都未初始化完成或初始化错误导致的发送异常