/**
* 属性文件加载对象
*/
private static PropertiesLoader loader = new PropertiesLoader(“j.properties”);
String path= loader.getProperty(“name”);
if(path==null){
/**
*getRealPath(“/”) 获取实际路径,项目在容器中的实际发布运行的根路径。
- PS:文件分隔符(在 UNIX 系统中是“/”),window 是”\”
*Window: D:\apache-tomcat-7.0\webapps
*Linux: D:/apache-tomcat-7.0/webapps
linux下需 .path.replaceAll("/","\\\\") ;
*/
path=ServletContextFactory.getServletContext().getRealPath("/");
File file = new File(path);
String [] fileName = file.list();
File [] files = file.listFiles();
for(File a:files)
{
if(a.isDirectory())
{
}
}
本文介绍了一种从属性文件加载配置并获取实际路径的方法。使用PropertiesLoader类加载名为j.properties的属性文件,并从中读取name对应的路径。如果未找到,则通过ServletContext获取应用的实际根路径。
5049

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



