struts2 多文件上传
来源:互联网 发布:java json tobean 编辑:程序博客网 时间:2024/05/21 17:21
struts2 多文件上传
以下是使用多线程上传文件的实验版,理想情况下的多文件上传使用针对性开发的组件比较好。
public class UploadFileMutilAction extends ActionSupport {
private File[] file;
private String[] fileFileName;
private String[] fileContentType;
private String path;
@Override
public String execute() throws Exception {
String realPath = ServletActionContext.getServletContext().getRealPath(path);
int poolSize = file.length;
ExecutorService es = Executors.newFixedThreadPool(poolSize);
for (int j = 0; j < poolSize; j++) {
Runnable r = new UploadFileMutilThread(file[j], fileFileName[j], realPath);
es.execute(r);
}
es.shutdown();
return SUCCESS;
}
public File[] getFile() {
return file;
}
public void setFile(File[] file) {
this.file = file;
}
public String[] getFileFileName() {
return fileFileName;
}
public void setFileFileName(String[] fileFileName) {
this.fileFileName = fileFileName;
}
public String[] getFileContentType() {
return fileContentType;
}
public void setFileContentType(String[] fileContentType) {
this.fileContentType = fileContentType;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
public class UploadFileMutilThread implements Runnable {
private File file;
private String FileName;
private String saveDir;
public UploadFileMutilThread(File files, String fileNames, String saveDir) {
this.file = files;
FileName = fileNames;
this.saveDir = saveDir;
}
@Override
public void run() {
File f = new File(saveDir);
if (!f.exists()) {
f.mkdirs();
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(new FileOutputStream(new File(f, FileName)));
byte[] b = new byte[2024];
int i = -1;
while ((i = bis.read(b)) != -1) {
bos.write(b);
}
bis.close();
bos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
bis.close();
bos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
- Struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- Struts2多文件上传
- Struts2多文件上传
- Struts2 多文件上传
- struts2多文件上传
- struts2 多文件上传
- Struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- struts2多文件上传
- 职业生涯规划的意义
- java_jdbc_基本连接池
- Android 的布局文件中的注释
- 环形缓冲区的实现原理
- const char*, char const*, char*const的区别问题
- struts2 多文件上传
- 如何禁止或暂停Windows的自动屏保、休眠等节电模式
- Endeca integratorETL安装部署
- int main(int argc, char*argv[])参数的作用
- uva 10305 基本拓扑排序
- 黑马程序员---IO流(字符流Writer、Reader)
- 设计模式-decorator模式
- 小爬虫——下载给定网页上的图片
- Win7下硬盘安装Ubuntu双系统(重新分区)