absolutePath为"C:\apache-tomcat-6.0.37\...后面省略";
在tomcat下用Java去File file = new File(absolutePath+"\"+fileName),然后打印日志会发现在绝对路径前面会多出来一个bin的路径,System.out.println(file.getAbsolutePath()); 为 "C:apache-tomcat-6.0.37bin???C:apache-tomcat-6.0.37..."+fileName,因为这个路径是错误的,所以新建文件就报错了。
正确处理为:把absolutePath+"\"+fileName 最前面的"C:\apache-tomcat-6.0.37\"去掉,改为"..\..\",即返回上两级菜单,再用剩下的路径去新建文件,这样文件就可以新建出来了。
String absolutePath = "C:\apache-tomcat-6.0.37\...后面省略"; File file = new File(absolutePath+"\"+fileName); System.out.println(file.getAbsolutePath()); //"C:apache-tomcat-6.0.37bin???C:apache-tomcat-6.0.37..."+fileName //正确如下 String absolutePath = "..\..\...后面省略"



