[英]Download and read on a large csv file in java Spring Rest service
我有一個Spring Rest服務,每隔10分鍾就會定期運行。 服務知道存儲在遠程服務器上的文件的路徑。 文件大小約為2GB。 Service獲取文件,然后讀取文件的內容,然后根據文件內容操作數據庫。 彈簧休息服務獲取大文件並對其內容進行操作的最佳方法是什么。
使用Apache File utils,
從在線下載1 GB文件的示例代碼如下,
package com.jai.download;
import java.io.File;
import java.net.URL;
import org.apache.commons.io.FileUtils;
public class FileDownload {
public static void main(String[] args) {
File file = new File("c:/jj/1gb.zip");
URL url;
try {
url = new URL("http://download.thinkbroadband.com/1GB.zip");
long start = System.currentTimeMillis();
System.out.println("Downloading....");
FileUtils.copyURLToFile(url, file);
long end = System.currentTimeMillis();
System.out.println("Completed....in ms : " + (end - start));
} catch (Exception e) {
e.printStackTrace();
}
}
}
我的互聯網速度為100 Mbps,它在94秒內下載了這個1GB文件。 一旦下載了這樣的csv文件,您就可以閱讀其內容,進行業務邏輯檢查並采取適當的措施。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.