为了找到.propertie文件,这么写的:classPath = URLDecoder.decode(DBService.class.getResource("/").getFile(), "utf-8"); //报错
Properties props = new Properties();
File file = new File(classPath + "extend.properties");
props.load(new FileInputStream(file));---------------------------------
DBService.class.getResource("/") //报错
DBService.class.getResource("/").getFile()DBService是上面代码所在的类名。上面的代码 WINDOWS下运行好好的,能得到资源路径,但是打成.jar后放到linux下就不行了,DBService.class.getResource("/") 为 null ,这怎么办啊?比较少用Linux, 各位帮我看看。谢谢。
Properties props = new Properties();
File file = new File(classPath + "extend.properties");
props.load(new FileInputStream(file));---------------------------------
DBService.class.getResource("/") //报错
DBService.class.getResource("/").getFile()DBService是上面代码所在的类名。上面的代码 WINDOWS下运行好好的,能得到资源路径,但是打成.jar后放到linux下就不行了,DBService.class.getResource("/") 为 null ,这怎么办啊?比较少用Linux, 各位帮我看看。谢谢。
propertie = new Properties();
String path = PropertyReader.class.getResource("/")
.getPath().toString();
path = path.replace("%20", " ");
Properties sysProperties = System.getProperties();
Object object = sysProperties.get("os.name");
if ("Windows XP".equals(String.valueOf(object))) {
inputFile = new FileInputStream(path.substring(1)
+ filePath);
} else {
inputFile = new FileInputStream(path
+ filePath);
}
sysProperties = null;
propertie.load(inputFile);
inputFile.close(); }