问题 A: FileStream读文件

题目描述

使用FileStream类,编写一个控制台应用,能够读取当前文件夹下myFile.dic文件内容,并在屏幕上显示。

输入

输出

文件内容

样例输入

样例输出

hello world!

hi ,good

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace text
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "myFile.dic";
            FileStream fs = new FileStream(path,FileMode.Open, FileAccess.Read);
            long i = fs.Length;
            byte[] b = new byte[fs.Length];
            fs.Read(b, 0, b.Length);
            fs.Dispose();
            UTF8Encoding tmp = new UTF8Encoding();
            Console.WriteLine(tmp.GetString(b));
            Console.ReadKey();
        }
    }
}

  

猜你喜欢

转载自www.cnblogs.com/mjn1/p/12890918.html