C#用流讀寫大文件

Code tells all:

成都創(chuàng)新互聯(lián)主要為客戶提供服務(wù)項目涵蓋了網(wǎng)頁視覺設(shè)計、VI標(biāo)志設(shè)計、全網(wǎng)營銷推廣、網(wǎng)站程序開發(fā)、HTML5響應(yīng)式重慶網(wǎng)站建設(shè)公司、手機網(wǎng)站開發(fā)、微商城、網(wǎng)站托管及成都網(wǎng)站維護、WEB系統(tǒng)開發(fā)、域名注冊、國內(nèi)外服務(wù)器租用、視頻、平面設(shè)計、SEO優(yōu)化排名。設(shè)計、前端、后端三個建站步驟的完善服務(wù)體系。一人跟蹤測試的建站服務(wù)標(biāo)準(zhǔn)。已經(jīng)為紗窗行業(yè)客戶提供了網(wǎng)站改版服務(wù)。

using System;
using System.IO;

namespace CSharpTest
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream fsRead = File.OpenRead(@"D:\test\in.txt");
            FileStream fsWrite = File.OpenWrite(@"D:\test\out.txt");

            byte[] buf = new byte[1024 * 8];
            int total = 0;
            int size = 0;
            do 
            {
                //注意第二個參數(shù)是在buffer中的偏移量,不是在文件中的偏移量
                size = fsRead.Read(buf, 0, buf.Length);
                fsWrite.Write(buf, 0, size);
                total += size;
            }while (size > 0);

            if (total != fsRead.Length)
            {
                Console.WriteLine("Error: total != fsRead.Length");
            }

            fsRead.Close();
            fsWrite.Close();

            Console.Write("GAME OVER!");
            Console.ReadKey();
        }
    }
}

相關(guān)閱讀:

1、FileStream.Read 方法

2、FileStream.Write 方法

*** walker *** 

文章標(biāo)題:C#用流讀寫大文件
當(dāng)前網(wǎng)址:http://www.muchs.cn/article36/phohsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站App設(shè)計、定制開發(fā)、營銷型網(wǎng)站建設(shè)網(wǎng)站排名、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司