• <em id="6vhwh"><rt id="6vhwh"></rt></em>

    <style id="6vhwh"></style>

    <style id="6vhwh"></style>
    1. <style id="6vhwh"></style>
        <sub id="6vhwh"><p id="6vhwh"></p></sub>
        <p id="6vhwh"></p>
          1. 国产亚洲欧洲av综合一区二区三区 ,色爱综合另类图片av,亚洲av免费成人在线,久久热在线视频精品视频,成在人线av无码免费,国产精品一区二区久久毛片,亚洲精品成人片在线观看精品字幕 ,久久亚洲精品成人av秋霞

            文件切割(PDF文件分割)

            更新時間:2023-03-02 12:38:35 閱讀: 評論:0

            #頭條創作挑戰賽#

            一、如何對一個大的文件進行一個切割

            import lombok.extern.slf4j.Slf4j;import org.springframework.stereotype.Component;import org.springframework.util.StringUtils;import java.io.*;import java.util.ArrayList;import java.util.List;/** * 處理csv文件類,進行將大文件進行分割 */@Component@Slf4jpublic class SplitFileUtil { public final static int line_num_split_file = 20000; public static final String _encoding = "GB2312"; /** * @param sourceFileUrl 源路徑 * @param targetPath 目標路徑 * @return * @throws IOException */ public static List<String> parateFileByLine(String sourceFileUrl, String targetPath) throws IOException { List<String> filenames = new ArrayList<>(); int file_count; //獲取文件總行數 long lineNum = getFileLineNum(sourceFileUrl); //不做分文件處理 Constants.line_num_per_file;自定義的常量 if (lineNum <= line_num_split_file) { filenames.add(sourceFileUrl); } el { //分割文件 if (lineNum % line_num_split_file == 0) { file_count = (int) (lineNum / line_num_split_file); } el { file_count = (int) (lineNum / line_num_split_file + 1); } Long[] countArray; if (file_count > Constants.max_file_count) { file_count = Constants.max_file_count; //將每個文件的起始索引記錄下來 countArray = new Long[file_count]; long file_start_index; int line_num_split_file; if (lineNum % file_count == 0) { line_num_split_file = (int) (lineNum / file_count); } el { line_num_split_file = (int) (lineNum / file_count + 1); } for (int i = 0; i < file_count; i++) { file_start_index = (i + 1) * line_num_split_file; countArray[i] = file_start_index; } } el { //將每個文件的起始索引記錄下來 countArray = new Long[file_count]; long file_start_index = 0; for (int i = 0; i < file_count; i++) { file_start_index = (i + 1) * line_num_split_file; countArray[i] = file_start_index; } } /*處理文件*/ InputStreamReader fr = null; BufferedReader br = null; try { fr = new InputStreamReader(new FileInputStream(sourceFileUrl), _encoding); br = new BufferedReader(fr); int count = 0; int _index = 0; String rec;// 一行 List<String> result = new ArrayList<>(); //讀取掉第一行數據,第一行為標題 br.readLine(); // 讀取一行 while ((rec = br.readLine()) != null) { count++; result.add(rec); if (count == countArray[_index]) { //一次性寫入文件 String targetFile = targetPath + "data_part_" + _index + ".csv"; writeCsv(targetFile, result); result.clear(); _index++; filenames.add(targetFile); } } if (result.size() > 0) { String targetFile = targetPath + "data_part_" + (file_count - 1) + ".csv"; writeCsv(targetFile, result); result.clear(); filenames.add(targetFile); } } catch (Exception e) { e.printStackTrace(); } finally { if (!StringUtils.isEmpty(br)) { br.clo(); } if (!StringUtils.isEmpty(fr)) { fr.clo(); } } } return filenames; } /** * @param csvFile 輸出的文件 * @param contentList 輸出的內容 * @throws IOException */ public static void writeCsv(String csvFile, List<String> contentList) throws IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), _encoding), 1024); for (int i = 0; i < contentList.size(); i++) { String str = contentList.get(i); bw.write(str); bw.newLine(); } bw.flush(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (!StringUtils.isEmpty(bw)) { bw.clo(); } } } /** * @param filename 獲取文件的行數 * @return * @throws IOException */ public static long getFileLineNum(String filename) throws IOException { long time1 = System.currentTimeMillis(); //取出文件總行數 long count = 0; InputStreamReader fr = null; BufferedReader br = null; try { fr = new InputStreamReader(new FileInputStream(filename), _encoding); br = new BufferedReader(fr); // 讀取一行 while (br.readLine() != null) { count++; } } catch (Exception e) { e.printStackTrace(); } finally { if (!StringUtils.isEmpty(br)) { br.clo(); } if (!StringUtils.isEmpty(fr)) { fr.clo(); } } long time2 = System.currentTimeMillis(); log.info("getFileLineNum=={} time is:{}", count, (time2 - time1)); return count; }}

            實現分割后寫入文件中

            實現讀取文件的行數

            本文發布于:2023-02-28 21:10:00,感謝您對本站的認可!

            本文鏈接:http://www.newhan.cn/zhishi/a/1677731915101204.html

            版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。

            本文word下載地址:文件切割(PDF文件分割).doc

            本文 PDF 下載地址:文件切割(PDF文件分割).pdf

            標簽:文件分割   文件   PDF
            相關文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網旗下知識大全大全欄目是一個全百科類寶庫! 優秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 日本高清一区免费中文视频| 99国产精品自在自在久久| 欧美精品亚洲精品日韩精品| 亚洲欧美另类精品久久久| 激情综合色综合啪啪开心| 国产精品久久久亚洲456| 黄色不卡视频一区二区三区| 亚洲免费的福利片| 99久久99视频只有精品| 四虎国产精品永久在线| 国色天香中文字幕在线视频| 亚洲欧美色综合影院| 欧美白妞大战非洲大炮| 国产美女裸体无遮挡免费视频下载| 免费国产精品黄色一区二区| 日本国产精品第一页久久| 国产一区国产精品自拍| 伊人狠狠色j香婷婷综合| 久久99精品一久久久久久| 国产三级精品三级在线看| 亚洲欧美色综合影院| 久久精品国产最新地址| 永久免费AV无码网站YY| mm1313亚洲国产精品| 97视频精品全国免费观看| 久久se精品一区精品二区国产| 亚洲成人av免费一区| 亚洲国产中文字幕精品| 在线观看日本亚洲一区| 最新国产精品亚洲| 午夜国产一区二区三区精品不卡| 亚洲成a人片在线观看久| 色8久久人人97超碰香蕉987| 国产无遮挡又黄又爽不要vip软件| 最近高清中文在线字幕在线观看| 吉川爱美一区二区三区视频| 精品无码一区二区三区电影| 一区二区三区一级黄色片| 久久综合久中文字幕青草| japanese无码中文字幕| 精品一区二区三区四区色|