vb.net 如何将流写入文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7929395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:45:55  来源:igfitidea点击:

How to write a Stream to file?

vb.netstream.net-2.0

提问by Jimmy D

I have an embedded DLL in my app and I need to write it to the filesystem at runtime. I have this so far:

我的应用程序中有一个嵌入式 DLL,我需要在运行时将其写入文件系统。到目前为止我有这个:

Dim _assembly As Assembly = Assembly.GetExecutingAssembly()
Dim _rawstream As Stream = _assembly.GetManifestResourceStream("MyFile.dll")

I just need to write _rawstream to a file now.

我现在只需要将 _rawstream 写入文件。

EDIT: This has to be .NET Framework 2 and CopyTo does not exist :(

编辑:这必须是 .NET Framework 2 并且 CopyTo 不存在:(

采纳答案by Jimmy D

My.Computer.FileSystem.WriteAllBytes(output file, My.Resources.resourcename, False)

回答by Oded

Use a FileStreamand write to it.

使用 aFileStream并写入它。

Dim fs As new FileStream("path to new file.dll", FileMode.Create)

_rawstream.CopyTo(fs)

Edit:

编辑:

For pre 4.0 see this.

对于 4.0 之前的版本,请参阅

回答by GazTheDestroyer

using (FileStream fileStream = File.OpenWrite("MyFile.bin"))
{
    _rawstream.CopyTo(fileStream);
}

EDIT: Oops, sorry, that's C# but the VB should be similar

编辑:哎呀,对不起,那是 C#,但 VB 应该是相似的