ServletContextFactory.getServletContext().getRealPath("/")的作用

来源:互联网 发布:电池优化 编辑:程序博客网 时间:2024/05/22 03:51

/**
* 属性文件加载对象
*/
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())            {            }        }
阅读全文
0 1
原创粉丝点击