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
How to write a Stream to file?
提问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 FileStream
and 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 应该是相似的