C#读文件操作

来源:互联网 发布:别墅设计软件下载 编辑:程序博客网 时间:2024/05/20 00:13
using System;using System.IO;namespace IO操作{    class Program    {        private const string FILE_NAME="IO.txt";        static void Main(string[] args)        {            if (!File.Exists(FILE_NAME))            {                Console.WriteLine("{0}does not exists!",FILE_NAME);                Console.ReadLine();                return;            }            //方法一:            //FileStream FS = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);            //BinaryReader BR = new BinaryReader(FS);            //for (int i = 0; i < 1; i++)            //{            //    Console.WriteLine(BR.ReadString());            //}            //BR.Close();            //FS.Close();            //Console.ReadLine();            //方法一:            using (StreamReader SR = File.OpenText(FILE_NAME))            {                string input;                while ((input = SR.ReadLine()) != null)                {                    Console.WriteLine(input);                }                Console.WriteLine("The end of the txt");                Console.ReadLine();                SR.Close();            }        }    }}

0 0
原创粉丝点击