首页 > Windows开发 > 详细

C#读文件操作

时间:2015-06-09 11:49:01      阅读:212      评论:0      收藏:0      [点我收藏+]
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();
            }
        }
    }
}

C#读文件操作

原文:http://blog.csdn.net/lucky51222/article/details/46424313

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!