日期:2014-05-17  浏览次数:20693 次

读文件路径问题求教!!!!!!!!!!!!!!
web 项目

项目名:ftest

包 com.common 下类:Tool.java

Tool.java中方法:generate(HttpServletRequest request)

根目录下文件:WebRoot\portal\global\help.txt

在Tool.java中new File(path) 读取help.txt,
请问path值是什么?

------解决方案--------------------
System.out.println(你的类名.class.getResource("/").getPath().replaceAll("%20", " "));
打印出来看看,稍微截取一下就可以了
------解决方案--------------------
String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + \help.txt;
 filePath = filePath.replaceAll("%20", " ");
------解决方案--------------------
String pathString = request.getRealPath("");
String path = pathString.substring(0, pathString.length() - 5);
String pathsum=path+File.separator+"portal"+File.separator+"global"+File.separator+help.txt

;