public class UploadAction extends ActionSupport {
// 封装的文件全名
private String myfileFileName;
// 封装的用户上传文件
private File myfile;
public String getMyfileFileName() {
return myfileFileName;
}
public void setMyfileFileName(String myfileFileName) {
this.myfileFileName = myfileFileName;
}
public File getMyfile() {
return myfile;
}
public void setMyfile(File myfile) {
this.myfile = myfile;
}
@Override
public String execute() throws Exception {
// 设置文件要另存的目录
File destFile =
new File(ServletActionContext
.getServletContext()
.getRealPath("/image")
+ "/" + this.getMyfileFileName());
//复制
//将左边的文件复制到右边的目录下
FileUtils.copyFile(this.getMyfile(), destFile);
return this.SUCCESS;
}
}
这是struts2的