2013년 12월 13일 금요일

[.Net] FileInfo 클래스를 이용한 파일 복사 프로그램

using System;
using System.IO;

public class csCopy
{
        public static void Main (String[] args)}
        {
                if (args.Length != 2)
                {
                        Console.WriteLine (" Using : csCopy src_filename dest_filename ");
                        return;
                }

                if (!File.Exists (args[0].ToString ()))
                {
                        Console.WriteLine ("{0} does not exist!", args[0].ToString ());
                        return;
                }

                if (File.Exists (args[1].ToString ()))
                {
                        Console.WriteLine ("{0} already exists!", args[1].ToString ());
                        return;
                }
               
                FileStream fsIn = new FileStream
                        (args[0].ToString (), FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader br = new BinaryReader (fsIn);
                FileStream fsOut = new FileStream (args[1].ToString (), FileMode.CreateNew);
                BinaryWriter bw = new BinaryWriter (fsOut);

                while (br.PeekChar () > -1)
                        bw.Write (br.ReadByte ());

                br.Close ();
                bw.Close ();
                fsIn.Close ();
                fsOut.Close ();
        }
}

댓글 없음:

댓글 쓰기