本文目錄一覽:
Java 批量大文件上傳下載如何實現?
解決這種大文件上傳不太可能用web上傳的方式,只有自己開發插件或是當門客戶端上傳,或者用現有的ftp等。
1)開發一個web插件。用於上傳文件。
2)開發一個FTP工具,不用web上傳。
3)用現有的FTP工具。
下面是幾款不錯的插件,你可以試試:
1)Jquery的uploadify插件。具體使用。你可以看幫助文檔。
java完成批量下載時,壓縮文件怎麼命名?
看你的代碼應該下載zip文件,對應的contentType 是application/x-zip-compressed
getResponse().setContentType(“application/octet-stream”);修改為getResponse().setContentType(“application/x-zip-compressed”);
JAVA 批量下載.zip
/**
* 報表查詢模塊 —-文件下載流
* @return
* @throws IOException
*/
public InputStream getInputStream() throws IOException {
InputStream ins = new FileInputStream(zipReports());
return ins;
}
/**
* 根據傳過來的報表編號壓縮文件為zip
* @param response
* @param serverPath
* @param str
* @throws IOException
*/
public File zipReports() throws IOException{
ListStatisticalReport srclist = new ArrayListStatisticalReport();
String[] pks = ids.split(“,”);
if(pks.length 0){
for(String pk : pks){
String[] str = pk.split(“\\|”);
StatisticalReport obj = new StatisticalReport();
obj.setCendat(str[0]);
obj.setOrgidt(str[1]);
obj.setRep_code(str[2]);
obj.setCurcde(str[3]);
srclist.add(obj);
}
}
StatisticalReport obj = new StatisticalReport();
obj.setReportList(srclist);
//查詢要下載的報表文件
ListStatisticalReport list = statisticalReportService.findReportList(obj);
//獲取應用在服務器上的根目錄
String path = request.getSession().getServletContext().getRealPath(System.getProperty(“file.separator”));
ListFile srcList = new ArrayListFile();
if(list.size() 0){
for(StatisticalReport statisticalReport : list){
File file = new File(statisticalReport.getFile_path());
if(file.exists()){
srcList.add(file);
}
}
}
Pim_sysUser user = (Pim_sysUser) session.getAttribute(SysConstant.SESSION_USER_DATA);
File zipfile = new File(path + System.getProperty(“file.separator”) + user.getLogid() + “REPORT.zip”);
if(zipfile.exists()){
zipfile.delete();
zipfile.createNewFile();
}
//FileTools.copyFile(, res.getString(“help_path”), newFormatFileName);// 上傳文件
ZipUtils.zipFiles(srcList, zipfile);
return zipfile;
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipUtils {
/**
* 將多個Excel打包成zip文件
*
* @param srcfile
* @param zipfile
*/
public static void zipFiles(ListFile srcfile, File zipfile) {
byte[] buf = new byte[2048];
try {
// Create the ZIP file
// Compress the files
if(srcfile.size() 0){
// 創建ZipOutputStream類對象
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
for (int i = 0; i srcfile.size(); i++) {
File file = srcfile.get(i);
FileInputStream in = new FileInputStream(file);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(file.getName()));// 寫入此目錄的Entry 創建新的進入點
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) 0) {
out.setLevel(9);
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
out.close();
}else{
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
out.putNextEntry(new ZipEntry(” “));
out.closeEntry();
out.close();
}
// Complete the ZIP file
} catch (IOException e) {
e.printStackTrace();
}
}
}
JAVA 如何一次下載多個文件
創建多線程下載
如果說方便下載,是打包再下載
~~~~~~~~~~~~~~~~~~~~~~
java ftp批量下載異常
Thread-3出現空指針異常。也就是說你在多線程運行過程中第三個線程出現問題。可能溢出之類的。Thread-3是系統在你沒有給線程命名的情況下系統自動給你的線程命名
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/296103.html