这个问题在Resin下是不存在的,但在Tomcat下却会变成这样,请问如何才可以解决??急!!!!!在线等!!!

解决方案 »

  1.   

    是我自己定的.properties文件.同样的程序,在Resin下是从来没有这种问题的,但这次必须要把程序移到Tomcat下,竟然出现这种问题.
    ==================================
    【读取资源文件--------->】
    private void init() {
    p = new Properties();
    try {
    InputStream is = PropertiesInfo.class.getResourceAsStream(propertiesFile);
    p.load(is);
    is.close();
    }catch(Exception e) {
    e.printStackTrace();
    }
    }
    【读key值--------->】
    public String getKeyValue(String key) {
    init();
    String keyValue;
    if(key == "" || key.equals("")) {
    keyValue = "null";
    }else {
    keyValue = p.getProperty(key, "null");
    }
    p.clear();
    return keyValue;
    }
    【修改key值-------->】
    public boolean setKeyValue(String key, String value) {
    init();
    boolean  = true;
    try {
    p.setProperty(key, value);
    java.net.URL url = PropertiesInfo.class.getResource("");  
    System.out.println(url.getPath());
    FileOutputStream fos = new FileOutputStream(url.getPath() + propertiesFile);
    p.store(fos, "");
    fos.close();
    p.clear();
    }catch(IOException e) {
     = false;
    e.printStackTrace();
    }
    return ;
    }
      

  2.   

    new PropertiesInfo().setKeyValue("key1", "hahahaha");
    new PropertiesInfo().getKeyValue("key1");
      

  3.   

    谢谢我爱花猫!!这样就可以了.
    Tomcat和Resin的机制到底是有些差别,加载对象的过程不太一样.