【问题标题】:Writing a stream of content to file in c#在c#中将内容流写入文件
【发布时间】:2020-05-17 10:18:51
【问题描述】:

我有一个包含内容流的变量。 变量指定如下图,

Task<Stream> tempStream = ....

具体来说,这个 tempStream 变量保存了一个 A pdf 流。

我想将此流写入文件。如何在 c# 中做到这一点?

【问题讨论】:

    标签: c# .net file pdf stream


    【解决方案1】:

    以下应该有效:

     path = @"Path\\to\\output";    
     using (FileStream outputFileStream = new FileStream(path, FileMode.Create))
     {
         tempStream.CopyTo(outpoutFileStream);
     }
    

    【讨论】:

    • 感谢您的回复,但我收到错误 Task 不包含 CopyTo 的定义。关于如何解决这个问题的任何想法?
    • 你指的这个tempStream是一个返回流的Task。您应该等待该任务并将 tempStream 声明为 Stream 类型。
    • 我尝试添加 Result.CopyTo 并且它也有效。在这里等待更好的方法吗?
    • 这可能是最好的方法,请进一步了解 Async/Await here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 2015-08-20
    • 1970-01-01
    相关资源
    最近更新 更多