■ Stream 클래스에서 스트림을 복사하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System.IO; #region 스트림 복사하기 - CopyStream(source, target) /// <summary> /// 스트림 복사하기 /// </summary> /// <param name="source">소스 스트림</param> /// <param name="target">타겟 스트림</param> /// <returns>쓰기 바이트 수</returns> public long CopyStream(Stream source, Stream target) { byte[] bufferByteArray = new byte[1024]; long totalByteCountRead = 0L; int byteCountRead = 0; while((byteCountRead = source.Read(bufferByteArray, 0, bufferByteArray.Length)) > 0) { target.Write(bufferByteArray, 0, byteCountRead); totalByteCountRead += byteCountRead; } return totalByteCountRead; } #endregion |