InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName); prop.load(in); prop.setProperty(propertyName, propertyVlaue); String url = PropertiesUtils.class.getClassLoader().getResource(fileName).toString().substring(6); File file = new File(url);
substring(6)的作用是去掉取得路径的/file: