當前位置:首頁 » 編程語言 » java文件的批量下載

java文件的批量下載

發布時間: 2022-05-27 18:21:05

java ftp上批量下載。。。如何和本地文件對應比較。。

比較文件名、比較文件大小,或者比較文件位元組序列。最絕的方法是比較文件的MD5值!

⑵ Java 批量大文件上傳下載如何實現

解決這種大文件上傳不太可能用web上傳的方式,只有自己開發插件或是當門客戶端上傳,或者用現有的ftp等。
1)開發一個web插件。用於上傳文件。
2)開發一個FTP工具,不用web上傳。
3)用現有的FTP工具。
下面是幾款不錯的插件,你可以試試:
1)Jquery的uploadify插件。具體使用。你可以看幫助文檔。

⑶ JAVA 如何一次下載多個文件

創建多線程下載
如果說方便下載,是打包再下載
~~~~~~~~~~~~~~~~~~~~~~

⑷ java 實現文件批量上傳下載實現方法 以及優勢缺點

File file = new File(path);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
StringBuffer buffer = new StringBuffer();
while ((tempString = reader.readLine()) != null) {
buffer.append(tempString);
}
reader.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {

}
}
}
return null;

⑸ 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{
List<StatisticalReport> srclist = new ArrayList<StatisticalReport>();
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);
//查詢要下載的報表文件
List<StatisticalReport> list = statisticalReportService.findReportList(obj);
//獲取應用在伺服器上的根目錄
String path = request.getSession().getServletContext().getRealPath(System.getProperty("file.separator"));
List<File> srcList = new ArrayList<File>();
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.File(, 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(List<File> 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();
}
}
}

⑹ 請問如何在不用struts框架,只用JSP、serverlet、java的情況下實現文件的批量下載,謝謝

批量下載是什麼意思啊?

可以提交給一個servlet,然後把文件流寫入到response中,這和用不用struts框架沒有關系。
出現亂碼,是下載流里的字元集沒有設置,具體的記不清了,屬性方法里挨個試也出來了。

看你的意思好象是,一個頁面上有多個checkbox選擇,點下載按鈕,把選中的都下載下來,
建議多做一個壓縮的功能,把選擇的做成一個壓縮包。只下載一次,如果連續彈出多個下載框的話,對性能的影響有些大。

⑺ 通過java實現文件下載

在jsp/servlet中斷點/多線程下載文件
<%@ page import="java.io.File" %><%@ page import="java.io.IOException" %><%@ page import="java.io.OutputStream" %><%@ page import="java.io.RandomAccessFile" %><%! public void downloadFile(HttpServletRequest request, HttpServletResponse response, File file) throws IOException { RandomAccessFile raf = new RandomAccessFile(file, "r"); java.io.FileInputStream fis = new java.io.FileInputStream(raf.getFD()); response.setHeader("Server", "www.trydone.com"); response.setHeader("Accept-Ranges", "bytes"); long pos = 0; long len; len = raf.length(); if (request.getHeader("Range") != null) { response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); pos = Long.parseLong(request.getHeader("Range") .replaceAll("bytes=", "") .replaceAll("-", "") ); } response.setHeader("Content-Length", Long.toString(len - pos)); if (pos != 0) { response.setHeader("Content-Range", new StringBuffer() .append("bytes ") .append(pos) .append("-") .append(Long.toString(len - 1)) .append("/") .append(len) .toString() ); } response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", new StringBuffer() .append("attachment;filename=\"") .append(file.getName()) .append("\"").toString()); raf.seek(pos); byte[] b = new byte[2048]; int i; OutputStream outs = response.getOutputStream(); while ((i = raf.read(b)) != -1) { outs.write(b, 0, i); } raf.close(); fis.close(); }%><% String filePath = request.getParameter("file"); filePath = application.getRealPath(filePath); File file = new File(filePath); downloadFile(request, response, file);%>
是否可以解決您的問題?

⑻ java爬蟲htmluinit框架批量下載文件

我用Jsoup寫爬蟲,一般遇到html返回沒有的內容。但是瀏覽器顯示有的內容。都是分析頁面的http請求日誌。分析頁面JS代碼來解決。
1、有些頁面元素被隱藏起來了->換selector解決
2、有些數據保存在js/json對象中->截取對應的串,分析解決
3、通過api介面調用->偽造請求獲得數據
還有一個終極方法
4、使用phantomjs或者casperjs這種headless瀏覽器

⑼ java ftp批量下載異常

我之前也遇到過這樣的事,通過FTP獲取文件的二進制流有限制,獲取第二個流的時候需要斷掉鏈接後再重新連接伺服器讀取流

⑽ java response.getOutputStream()實現多個文件下載,已經拿到兩個位元組數組的list,下載的時候如何同時下載

可以一個介面傳多個文件,每個文件中間用特定符號拆分,也可以寫一個介面前端多次調用,將請求頭的文件格式改為blob,前端獲取文件流後調用下載

熱點內容
android訪問網路許可權 發布:2025-02-12 14:55:20 瀏覽:88
原神文件夾 發布:2025-02-12 14:50:15 瀏覽:800
c語言數字翻譯 發布:2025-02-12 14:45:54 瀏覽:497
暗區突圍為什麼顯示伺服器維修 發布:2025-02-12 14:45:53 瀏覽:247
翻譯分為匯編和編譯 發布:2025-02-12 14:29:12 瀏覽:233
什麼是新聞編譯 發布:2025-02-12 14:23:12 瀏覽:853
如何查看手機存儲 發布:2025-02-12 14:21:15 瀏覽:50
cacti自定義腳本 發布:2025-02-12 14:21:13 瀏覽:313
編譯安卓步驟 發布:2025-02-12 14:19:39 瀏覽:222
php把數組分組 發布:2025-02-12 14:19:37 瀏覽:280