c\#텍스트 파일 을 바 이 너 리 로 읽 습 니 다.


using System;
using System.IO;

public class FileApp
{
    public static void Main()
    {
        // myfile.txt,
        FileStream fsMyfile = new FileStream("myfile.txt" , FileMode.Create, FileAccess.ReadWrite);

        // ,
        StreamWriter swMyfile = new StreamWriter(fsMyfile);

        //
        swMyfile.WriteLine("Hello, World");
        swMyfile.WriteLine("abcdefghijklmnopqrstuvwxyz");
        swMyfile.WriteLine("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        swMyfile.WriteLine("0123456789");

        // ( )
        // ,
        swMyfile.Flush();

        //
        // ,
        StreamReader srMyfile= new StreamReader(fsMyfile);

        //
        srMyfile.BaseStream.Seek(0, SeekOrigin.Begin);

        //
        Console.WriteLine("**************** *********************");

        //
        string s1;
        while((s1 = srMyfile.ReadLine())!=null)
        {
            Console.WriteLine(s1);
        }
        Console.WriteLine();
        //


        //
        // ,
        BinaryReader brMyfile= new BinaryReader (fsMyfile);

        //
        brMyfile.BaseStream.Seek(0, SeekOrigin.Begin);

        //
        Console.WriteLine("**************** *********************");

        //
        Byte b1;
        while(brMyfile.PeekChar()>-1)
        {
            b1=brMyfile.ReadByte();
            // 13 "
", ;10 "\r",
            if(b1 != 13 && b1 != 10)
            {
                Console.Write("{0}",b1.ToString());
                Console.Write(".");
            }
            else
            {
                Console.WriteLine();
            }
        }
        Console.WriteLine("
");
        //

        // new
        brMyfile.Close();
        srMyfile.Close();
        fsMyfile.Close();

        //
        //
        Console.WriteLine("**************** *********************");

        FileInfo fiMyfile=new FileInfo("myfile.txt");
        Console.WriteLine(" : {0}",fiMyfile.Name);
        Console.WriteLine(" ( ) : {0}",fiMyfile.FullName);
        Console.WriteLine(" (bytes) : {0}",fiMyfile.Length);
        Console.WriteLine(" : {0}",fiMyfile.CreationTime);
    }
}

좋은 웹페이지 즐겨찾기