zoukankan      html  css  js  c++  java
  • C# 大文本拆分

    
    public static void SplitBigTxtFile(string filePath)
            {
                int lineOfEach = 500000;
                int fileIndex = 1;
    
                var outputFile = Path.GetFileNameWithoutExtension(filePath) + "_" + fileIndex + ".txt";
                string headerLine = "";
                int lineIndex = 1;
    
                StreamWriter sw = new StreamWriter(outputFile, false, Encoding.GetEncoding("gb2312"));
                using (StreamReader sr = new StreamReader(filePath, Encoding.GetEncoding("gb2312")))
                {
                    headerLine = sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        var line = sr.ReadLine();
                        lineIndex++;
                        sw.WriteLine(line);
    
                        if (lineIndex % lineOfEach == 0)
                        {
                            fileIndex++;
                            outputFile = Path.GetFileNameWithoutExtension(filePath) + "_" + fileIndex + ".txt";
                            sw.Flush();
                            sw.Close();
    
                            sw = new StreamWriter(outputFile, false, Encoding.GetEncoding("gb2312"));
                        }
                    }
                }
            }
    
  • 相关阅读:
    Mac国内源安装brew
    linux基础命令(二)
    运维查看命令
    初识数据库
    镜像/容器相关操作
    docker基本命令
    Docker简介及部署
    CF1599A Weights 构造
    CSP-S 2021 游记
    GeOP 1.0开发成!
  • 原文地址:https://www.cnblogs.com/LukeSteven/p/15476319.html
Copyright © 2011-2022 走看看