web项目 (dynamic web project ) 读取properties 文件时报错: FileNotFoundException: properties

①//properties.load(new FileInputStream("db.properties"));
②//properties.load(DBTools.class.getClassLoader().getResourceAsStream("db.properties"));
③properties.load(DBTools.class.getResourceAsStream("db.properties"));

注意:web项目中 路径和 java项目不同,这里web项目使用 ①方法较麻烦,上文中这样使用会报错。

使用②方法没啥问题,使用③方法时,properties文件要和 读取它的java文件放在一个文件夹里,见文首链接中内容。

web项目 和java项目路径的问题见:http://serisboy.iteye.com/blog/1319353

还有  Properties文件名首字母不能大写,