본문 바로가기
.Net

C# 텍스트 파일 복사 코드

by Dokon Jang 2016. 5. 31.
반응형

텍스트 파일 복사 코드입니다.

public void CopyFile(string sourceFileName, string targetFileName)
{
    StreamReader sr = null;
    StreamWriter sw = null;

    try
    {
	sr = new StreamReader(sourceFileName);
	sw = new StreamWriter(targetFileName);

	string str;
	while ((str = sr.ReadLine()) != null)
	{
	    sw.WriteLine(str);
	}
    }
    catch (Exception ex)
    {
	throw ex;
    }
    finally
    {
	try { sr.Close(); }
	catch { }

	try { sw.Close(); }
	catch { }
    }
}

 

반응형

댓글