FreamStream文件的分割

来源:互联网 发布:软件下载大全360 编辑:程序博客网 时间:2024/05/19 14:16

#region 文件分割
        static void Main(string[] args)
        {
            string file = @"x.txt";
            using (FileStream fileRead = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                //表示每个文件大小
                long length = (int)Math.Ceiling(file.Length / 3 * 1.0);
                byte[] bt=new byte[1024];
                for (int i = 0; i < 3; i++)
                {
                    int total = 0;
                    using (FileStream temp = new FileStream(file + i.ToString(), FileMode.Create, FileAccess.Write))
                    {
                        int count = 0;
                        while ((count = fileRead.Read(bt, 0, count)) > 0)
                        {
                            total += count;
                            temp.Write(bt, 0, count);
                            if (total >= length)
                            {
                                break;
                            }
                        }

                    }
                }
            }
            Console.WriteLine("0k");
            Console.ReadKey();
        }
#endregion

0 0
原创粉丝点击