zoukankan      html  css  js  c++  java
  • C#实现文本文件合并

    读取n个文本文件,把文件内容合并到一个文本文件中。主要用了FileStream的ReadByte和WriteByte方法:

    class FileCombine
    {
         public void CombineFile(String[] infileName,String outfileName)
         {     
                int b;
                int n=infileName.Length;
                FileStream[] fileIn=new FileStream[n];
                using (FileStream fileOut = new FileStream(outfileName, FileMode.Create))
                {
                    for (int i = 0; i < n; i++)
                    {
                        try
                        {
                            fileIn[i] = new FileStream(infileName[i], FileMode.Open);
                            while ((b = fileIn[i].ReadByte()) != -1)
                                fileOut.WriteByte((byte)b);
                        }
                        catch (System.Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            fileIn[i].Close();
                        }
                       
                    }
                }
         }
    }

    调用方法如下:

    class TestCombine
    {
         public static void Main(String[] args)
         {
             FileCombine c=new FileCombine();
             String[] file=new String[2];
             file[0]="aa.txt";
             file[1]="bb.txt";
             c.CombineFile(file,"cc.txt");
        }
    }

  • 相关阅读:
    synchronous_commit 参数的再次说明
    ubuntu 16.04 + zabbix 3.4 + postgresql pg_monz
    ubuntu 16.04 + zabbix 3.4 + postgresql shell
    ubuntu 16.04 + zabbix 3.4 + postgresql UserParameter
    ubuntu 16.04 + zabbix 3.4 + postgresql libzbxpgsql
    ubuntu 16.04 + zabbix 3.4 + zabbix agent
    ubuntu 16.04 + zabbix 3.4 + zabbix proxy
    ubuntu 16.04 + zabbix 3.4 + zabbix server
    apt-get、apt-cache的一些日常操作
    ubuntu 16.04 apt-get source 替换为 aliyun
  • 原文地址:https://www.cnblogs.com/zhouhb/p/2079868.html
Copyright © 2011-2022 走看看