C#学习第七天

  今天进行了C#的第五次学习,继续了解C#的相关知识:

文件的输入与输出

I/O类

image-20221014162202657

FileStream类

image-20221014162237302

image-20221014162248750

image-20221014162403517

  下面是一个FileSteam类的操作示例:

using System;
using System.IO;

namespace FileIOApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream F = new FileStream("test.dat",
            FileMode.OpenOrCreate, FileAccess.ReadWrite);

            for (int i = 1; i <= 20; i++)
            {
                F.WriteByte((byte)i);
            }

            F.Position = 0;

            for (int i = 0; i <= 20; i++)
            {
                Console.Write(F.ReadByte() + " ");
            }
            F.Close();
            Console.ReadKey();
        }
    }
}
posted @ 2022-10-14 16:25  信2005-2刘海涛  阅读(28)  评论(0编辑  收藏  举报