• <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://m.newhan.cn/zhishi/a/1677731915101204.html

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

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

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

            標簽:文件分割   文件   PDF
            相關文章
            留言與評論(共有 0 條評論)
               
            驗證碼:
            Copyright ?2019-2022 Comsenz Inc.Powered by ? 實用文體寫作網旗下知識大全大全欄目是一個全百科類寶庫! 優秀范文|法律文書|專利查詢|
            主站蜘蛛池模板: 国模无吗一区二区二区视频 | 午夜精品福利亚洲国产| 在线a级毛片无码免费真人| 曰韩亚洲AV人人夜夜澡人人爽| 99亚洲男女激情在线观看| 国产乱精品一区二区三区| 你拍自拍亚洲一区二区三区| 国产午夜在线观看视频播放| 男女性高爱潮免费网站| 精品亚洲成A人在线观看青青| 日本一区二区视频在线播放| 在线精品国产中文字幕| 亚洲成av人片天堂网老年人| 熟妇的味道hd中文字幕| 国产真人无码作爱视频免费| √天堂资源在线中文8在线最新版 亚洲午夜成人精品电影在线观看 日本高清视频网站www | 亚洲精品漫画一二三区| 久久99国产精品尤物| 日本亚洲一区二区精品久久| 免费大黄网站在线观看| 国产免费高清69式视频在线观看| 国产精品私拍99pans大尺度| 国产乱码日韩精品一区二区| 成人3d动漫一区二区三区| 乱60一70归性欧老妇| 精品国产成人三级在线观看| 久久久这里只有精品10| 国产欲女高潮正在播放| 波多野42部无码喷潮| 无码人妻丝袜在线视频| 日本高清在线观看WWWWW色| 精品国产成人国产在线视| 97天天摸天天爽天天碰| 女人香蕉久久毛毛片精品| 国产最新AV在线播放不卡| 色猫咪av在线观看| 丰满老熟妇好大bbbbb| 全球成人中文在线| 欧美午夜成人片在线观看| 亚洲av无码一区二区乱子仑| 亚洲偷自拍国综合|