小编Cam*_*mal的帖子

如何优化我的BinaryWriter?

我目前正在通过FTP传输文件的程序.我发送二进制文件,因为使用ASCII我不能发送特殊字符.

这是我目前的代码:

    using(BinaryReader bReader = new BinaryReader(srcStream))
    using (BinaryWriter bWriter = new BinaryWriter(destStream))
    {
        Byte[] readBytes = new Byte[1024];
        for(int i = 0; i < bReader.BaseStream.Length; i += 1024)
        {
            readBytes = bReader.ReadBytes(1024);
            bWriter.Write(readBytes);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我对这段代码的问题是:

  1. 它工作得很慢,有优化方法吗?
  2. 我要求EOF(EndOfFile)的方式似乎很奇怪,还有另一种优雅的选择吗?

非常感谢:D

c# ftp

2
推荐指数
1
解决办法
3984
查看次数

标签 统计

c# ×1

ftp ×1