以下是使用多线程上传文件的实验版
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)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
bis.close();
bos.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
}
相关推荐
struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载
struts2文件上传struts2文件上传struts2文件上传struts2文件上传struts2文件上传struts2文件上传struts2文件上传struts2文件上传
struts2文件上传实例,程序员宝典......
里面包括的是实现struts2文件上传所需要的全部jar包
Struts2文件上传
Struts2 文件上传
Struts2文件上传源码 Struts2文件上传源码 Struts2文件上传源码 Struts2文件上传源码 Struts2文件上传源码
struts2文件上传与下载,eclipse与myeclipse导入即可使用的代码,简单易懂,希望对你有帮助,喜欢的给个五星评价,谢谢!!!
Struts 2是通过Commons FileUpload文件上传。Commons FileUpload通过将HTTP的数据保存到临时文件夹,然后Struts使用fileUpload拦截器将文件绑定到Action的实例中。从而我们就能够以本地文件方式的操作浏览器上传的...
http://blog.csdn.net/johnjobs/article/details/8076832博文中附件的下载链接