您当前的位置: 首页 >  c#

刘一哥GIS

暂无认证

  • 5浏览

    0关注

    934博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#读文件操作

刘一哥GIS 发布时间:2015-06-09 11:12:36 ,浏览量:5

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();
            }
        }
    }
}
关注
打赏
1665586602
查看更多评论
立即登录/注册

微信扫码登录

0.0795s