package com.citycube.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
* 文件上传的测试
*
* @author ZuoShuai
*
* 创建于--2011-2-23
*/
public class UploadAction extends ActionSupport {
private File[] upload;
private String[] uploadFileName;
private String[] uploadContentType;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("come to this action..");
for (int i = 0; i < upload.length; i++) {
copy(upload[i], uploadFileName[i], uploadContentType[i]);
}
return SUCCESS;
}
public void copy(File file, String fileName, String contentType)
throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
System.out.println(fileName + "--" + contentType);
try {
in = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String realpath = ServletActionContext.getServletContext().getRealPath(
"/upload");
try {
out = new FileOutputStream(realpath + "\\" + fileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] bys = new byte[2048];
int length = -1;
// 读进
while ((length = in.read(bys)) != -1) {
out.write(bys, 0, length);
}
// 关闭
in.close();
out.close();
}
public File[] getUpload() {
return upload;
}
public void setUpload(File[] upload) {
this.upload = upload;
}
public String[] getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String[] uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String[] getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String[] uploadContentType) {
this.uploadContentType = uploadContentType;
}
}
struts 文件的上传下载 简要实现 下载过程传递中文实现
4星 · 超过85%的资源 需积分: 3 75 浏览量
2011-02-25
14:41:41
上传
评论
收藏 4.87MB RAR 举报
dsdddddddddddddddd
- 粉丝: 2
- 资源: 18
最新资源
- 基于Python的图像阴影检测与去除源码(高分期末大作业项目).zip
- 基于C++/Qt实现的井字棋游戏
- 基于 Python 编程语言的 Web 框架Django
- Python和Flask实现的基于体检数据的城市公共健康可视分析系统源码+使用说明.zip
- 基于python实现的华为智慧工地-安全帽检测
- buck-boost_2023-12-16_12-12-13.eprj
- 后端开发关于数据库和API开发的介绍
- 机器学习和数据挖掘课程设计-米其林餐厅数据挖掘管理系统源码+使用文档说明.zip
- html html html展示我与ai的对化
- 数据结构课程设计-全国交通出行咨询模拟系统C语言实现源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈