首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

File f = new File(filePath) f.exists() 替false 求大神

2011-12-25 
File f new File(filePath)f.exists() 为false 求大神现在是做头像剪切,先传一张在服务器,resources\upl

File f = new File(filePath) f.exists() 为false 求大神
现在是做头像剪切,先传一张在服务器,resources\upload\2011\10\12\123.png , 然后将这路径放到页面显示,截取后将resources\upload\2011\10\12\123.png 传入action,

在用 ServletActionContext.getRequest().getRealPath("")+resources\upload\2011\10\12\123.png  

得到的路径为:


String filaPath=F:\编程工具安装包\Tomcat\apache-tomcat-6.0.26-windows-x64\apache-tomcat-6.0.26\webapps\mmshuxia/resources/upload/2011/10/12/20115012175032CgSis6e.png

将上面的路径放硬盘里查找,文件存在

然后 File f = new File(filaPath);
  System.out.println(f.exists());

输出为 false


下面是tomcate配置:
<Connector port="8080" protocol="HTTP/1.1" 
  connectionTimeout="20000" 
  redirectPort="8443" URIEncoding="utf-8" useBodyEncodingForURI="true"/>
 

[解决办法]
System.getProperty("catalina.home")


获取到tomcat服务的路径
[解决办法]

Java code
ClassLoader.getSystemResourceAsStream() 

热点排行