日期:2014-05-17  浏览次数:21019 次

C#能不能进行流的转接?
把一个输入流直接转到一个输出流上,进行输出。

------解决方案--------------------
http://stackoverflow.com/questions/230128/best-way-to-copy-between-two-stream-instances
------解决方案--------------------
 var I = Console.OpenStandardInput();
            var o = Console.OpenStandardOutput();
            I.CopyTo(o,1);
------解决方案--------------------
public void CopyTo(Stream destination)
    {
      if (destination == null)
        throw new ArgumentNullException("destination");
      if (!this.CanRead && !this.CanWrite)
        throw new ObjectDisposedException((string) null, Environment.GetResourceString("ObjectDisposed_StreamClosed"));
      if (!destination.CanRead && !destination.CanWrite)
        throw new ObjectDisposedException("destination", Environment.GetResourceString("ObjectDisposed_StreamClosed"));
      if (!this.CanRead)
        throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream"));
      if (!destination.CanWrite)
        throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream"));
      this.InternalCopyTo(destination, 81920);
    }
    
     public void CopyTo(Stream destination, int bufferSize)
    {
      if (destination == null)
        throw new ArgumentNullException("destination");
      if (bufferSize <= 0)
        throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
      if (!this.CanRead && !this.CanWrite)
        throw new ObjectDisposedException((string) null, Environment.GetResourceString("ObjectDisposed_StreamClosed"));
      if (!destination.CanRead && !destination.CanWrite)
        throw new ObjectDisposedException("destination", Environment.GetResourceString("ObjectDisposed_StreamClosed"));
      if (!this.CanRead)
        throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream"));
      if (!destination.CanWrite)