InputStream is = Test1.class.getClassLoader().getResourceAsStream("/db.property");db.property放web-inf class下面,怎么就是读不出来

解决方案 »

  1.   

    getResourceAsStream是读取jar包中的资源用的吧
      

  2.   

    你的Test1类在jar包里?还是直接放在classes目录下?
      

  3.   

    你可以使用以下代码试一下:
    InputStream is = Test1.class.getResourceAsStream("db.property");
    主要是要把getClassLoader()去掉。如果还不行,那就需要把db.property文件放在与Test1.class相同的包下就可以了。