zoukankan      html  css  js  c++  java
  • C#分割文件内容

            static void ReadData(string sourcePath, string targetDirectory)
            {
                FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs, Encoding.Default);
                sr.BaseStream.Seek(0, SeekOrigin.Begin);
                string line = string.Empty;
                int seg = 0;
    
                while (line != null)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < 10000; i++)
                    {
                        line = sr.ReadLine();
                        if (line.Trim()=="GO")
                            break;
                        else
                            sb.AppendLine(line);
                    }
                    seg++;
                    string targetPath = targetDirectory + "\" + Path.GetFileNameWithoutExtension(sourcePath) + "_" + seg.ToString() + Path.GetExtension(sourcePath);
                    sb.AppendLine("GO");
                    sb.AppendLine();
                    WriteData(sb.ToString(), targetPath);
                }
                sr.Close();
                fs.Close();
            }
    
            static void WriteData(string str, string path)
            {
                FileStream aFile = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
                StreamWriter sw = new StreamWriter(aFile);
                sw.Write(str);
                sw.Close();
                aFile.Close();
            }
    

      

  • 相关阅读:
    Pandas 基础(8)
    Pandas 基础(7)
    Pandas 基础(6)
    Pandas 基础(5)
    Pandas 基础(4)
    python matplotlib 图表局部放大
    python 带小数点时间格式化
    emacs elpy代码补全功能
    spacemacs 初始安装报错
    视频加载logo 2
  • 原文地址:https://www.cnblogs.com/mikechang/p/7090445.html
Copyright © 2011-2022 走看看