咋上传图片找不到指定的路径呀?java.io.FileNotFoundException: \save\1.jpg (系统找不到指定的路径。)

struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts> <package name="default" extends="struts-default"> <action name="upload" class="Action.UploadAction"> <interceptor-ref name="fileUpload"> <param name="maximumSize"> 10000000 </param> <param name="allowedTypes"> image/gif,image/png,image/jpeg,image/jpg,image/pjpeg </param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <param name="savePath">/WebRoot/save</param> <result name="input">/pictures/fileUp.jsp</result> <result name="success">/pictures/fileUpSuccess</result> </action> </package></struts>
action类
package Action;
···········
public class UploadAction extends ActionSupport { private String title; private File upload; private String uploadcontentType; private String uploadFileName; private String savePath;················
public String execute()throws Exception{ FileOutputStream fos=new FileOutputStream(this.getSavePath()+"//"+this.getUploadFileName()); FileInputStream fis=new FileInputStream(this.getUpload()); System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); byte[] buffer=new byte[1024]; int len=0; while ((len=fis.read(buffer))>0){ fos.write(buffer,0,len); } fos.close(); return SUCCESS; }}

第1个回答  2014-03-09
好高科技的路径
第2个回答  2014-03-08
FileOutputStream fos=new FileOutputStream(this.getSavePath()+"//"+this.getUploadFileName());里面的"//"改成"/";或者用File.separator()代替追问

还是这个问题FileNotFoundException: \save\Desert.jpg (系统找不到指定的路径。),试了还没解决

本回答被提问者采纳
相似回答