日期:2014-05-20 浏览次数:20866 次
public String execute() throws Exception {
//文件保存的文件夹
String path = ServletActionContext.getRequest().getRealPath("/upload");
//得到上传的文件对象
InputStream is = new FileInputStream(file);
System.out.println("fileFileName:"+getFileFileName());//打印获取到的文件名称
System.out.println("fileContentType:"+getFileContentType());//打印获取到的文件类型
File rootPath = new File(path,getFileFileName());//封装文件路径和文件名
OutputStream os = new FileOutputStream(rootPath);//将文件输出到指定的文件夹
byte[] buffer = new byte[400];//新建字节对象
int length = 0;
//如果长度不为-1,则循环的读取文件对象
while(-1 != (length = is.read(buffer))){
os.write(buffer, 0, length);
}
//读写玩文件后,将输入输出流关闭
is.close();
os.close();
return Action.SUCCESS;
}