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();
        }

  

相关文章:

  • 2021-07-16
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2021-10-10
猜你喜欢
  • 2022-12-23
  • 2021-10-15
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2020-06-17
相关资源
相似解决方案