■ 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 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.IO; #region 스트림 복사하기 - CopyStream(source, target, copySize) /// <summary> /// 스트림 복사하기 /// </summary> /// <param name="source">소스 스트림</param> /// <param name="target">타겟 스트림</param> /// <param name="copySize">복사 크기</param> /// <returns>복사 바이트 수</returns> public int CopyStream(Stream source, Stream target, int copySize) { byte[] bufferByteArray = new byte[32763]; int byteCountCopied = 0; while(copySize > 0) { int byteCountRead = source.Read(bufferByteArray, 0, Math.Min(bufferByteArray.Length, copySize)); if(byteCountRead == 0) { break; } target.Write(bufferByteArray, 0, byteCountRead); copySize -= byteCountRead; byteCountCopied += byteCountRead; } return byteCountCopied; } #endregion |