바이너리 형태로 파일을 읽어 들여 복사하는 프로그램이다. 카피 할때 스레드를 이용해서 복사를 하였고, 닷넷에서 지원해 주는 카피 매서드는 이용하지 않고 구현해 보았다.
using System;
using System.IO;
using System.Text;
using System.Threading;
public class BCopy
{
private string originalFile;
private string copyFile;
private FileStream rs = null;
private FileStream ws = null;
private long fileSize = 0;
public BCopy(string ofile,string cfile)
{
this.originalFile = ofile;
this.copyFile = cfile;
try
{
this.rs = File.OpenRead(this.originalFile);
this.ws = new FileStream(this.copyFile,FileMode.Create);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
~BCopy()
{
rs.Close();
ws.Close();
}
public void Copy()
{
try
{
byte[] b = new byte[1024];
int count = 0;
while( (count = rs.Read(b,0,b.Length)) > 0)
{
ws.Write(b,0,count);
this.fileSize += count;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine("File size : " + this.fileSize);
}
}
public static void Main(string[] args)
{
if( args.Length != 2)
{
Console.WriteLine("Usang Args : app <orginal Filename> <copy Filename>");
return;
}
try
{
BCopy fileCopy = new BCopy(args[0],args[1]);
Thread copyThread = new Thread(new ThreadStart(fileCopy.Copy));
copyThread.Start();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
솔직히 별로 한것은 없고 읽은것을 쓰는데 하는것을 좀 오래 찾았아 ㅡ.ㅡ;
댓글을 달아 주세요