转:Java properties | FileNotFoundException: properties (系统找不到指定的文件。)

原文地址:https://blog.csdn.net/cor_twi/article/details/44514871

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文件名首字母不能大写,

猜你喜欢

转载自www.cnblogs.com/mumu122GIS/p/9852931.html