public static String[] getItemValue(String key) {
try {
// /D:/软件/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/BIRUNET/WEB-INF/classes/
String path = new CheckItems().getClass().getResource("/").getPath() ;
// D:/软件/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/BIRUNET/WEB-INF/
String substring = path.substring(1, path.length()-8);
// D:/软件/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/BIRUNET/WEB-INF/ITEMS/items.properties
substring = substring +"ITEMS/items.properties";
File files = new File(substring);
if(!files.exists()){
throw new RuntimeException("要读取的文件不存在");
}
String[] value = null;
inputFile = new FileInputStream(files);
propertie.load(inputFile);
inputFile.close();
if (propertie.containsKey(key)) {
value = propertie.getProperty(key).split(",");
return value;
} else
return value;
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}// end getValue( )
ssm 获取WEB-INF的绝对路径
最新推荐文章于 2021-03-02 18:28:21 发布
本文介绍了一个Java程序示例,该程序用于从特定路径下的items.properties文件中读取属性值,并根据提供的键返回相应的值数组。示例展示了如何处理文件读取过程中可能遇到的异常。
1030

被折叠的 条评论
为什么被折叠?



