首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#能不能进展流的转接

2013-11-26 
C#能不能进行流的转接?把一个输入流直接转到一个输出流上,进行输出。[解决办法]http://stackoverflow.com/q

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)
        throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream"));
      this.InternalCopyTo(destination, bufferSize);
    }

热点排行