请问如何读出这个message.properties文件,文件内容如下:
MSG_S0_0001="1234566777";
MSG_S0_0002="sssssss";希望给一个MSG_S0_0001,就能把后面的字符串的内容读出来,请问怎么能够做到哪?应该包含哪些包?
最好能给一些可以实现的代码,谢谢

解决方案 »

  1.   

    文件放在这个路径下:"WEB-INF/resource/message.properties"
      

  2.   

    Properties props = new Properties();
          try {
                InputStream in = Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream("message.properties");
                props.load(in);
                in.close();
            } catch (Exception e) {
            }
    System.out.println(props.getProperty("MSG_S0_0001"));
      

  3.   

    楼上的代码我试了一下,in返回的是空值,所以也没有打印出值来。还有我想知道,我能在程序中修改message.properties文件的内容吗?
      

  4.   

    另外MSG_S0_0001="1234566777";MSG_S0_0002="sssssss";不要加双引号。配置文件中直接写***=***就可以了。
      

  5.   


    最好这样写:
    public abstract class VaTextResource { 
        private final static String MSG_S0_0001= "1234566777";
    }
      

  6.   

    路径
    getResourceAsStream("../resource/message.properties");
      

  7.   

    改成这个路径也不行getResourceAsStream("../resource/message.properties");