Stream 연습

PUBLISHED
POSTED IN COMPUTING

Stream 연습

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

namespace FileStreamEx001
{
   class Program
   {
       static void Main(string[] args)
       {
           //FileCopy();
           //StreamReaderEx();

       }

       // 메인에서 실행
       //aaa.txt를 한줄씩 읽어서 화면에 표시
       private static void StreamReaderEx()
       {
           FileStream fs = new FileStream(@"d:\aaa.txt", FileMode.Open);
           StreamReader sr = new StreamReader(fs);
           fs.Seek(0, SeekOrigin.Begin);
           byte[] bb = new byte[10];
           fs.Read(bb, 0, 10);
           string str = Encoding.ASCII.GetString(bb);
           string st = "";

           while (st != null)
           {
               st = sr.ReadLine();
               Console.WriteLine(st);
           }
       }

       //메인에서 실행
       //파일복사 aaa.txt를 bbb.txt로 복사
       private static void FileCopy()
       {
           FileStream fs = new FileStream(@"d:\aaa.txt.", FileMode.Open);
           FileStream fs1 = new FileStream(@"d:\bbb.txt", FileMode.Create);
           byte[] bb = new byte[50];
           int count = 0;
           while ((count = (fs.Read(bb, 0, 50))) != 0)
           {
               fs1.Write(bb, 0, count);
           }
           fs1.Flush();
           fs.Close();
           fs1.Close();
       }
   }
}

입출력의 중요한 부분인 Stream을 뒤늦게 연습중이다.
써봐야 할것들이 얼마나 많은지 눈으로 다 읽지도 못했다.

Stream도 머리 아픈데 비동기 Method , Thread ...
아직 익혀야할 부분이 너무 많다.

내일부턴 작은 프로젝트...
잘 할 수 있을런지 자신이 없다.

TRACKBACK URL : 이 글에는 트랙백을 보낼 수 없습니다