gpt4 book ai didi

vb.net - 将音频文件从 Windows 窗体应用程序资源复制到硬盘

转载 作者:行者123 更新时间:2023-12-02 22:23:17 25 4
gpt4 key购买 nike

使用 Visual Studio 2013

我一直在尝试从 vb.net Windows 窗体应用程序复制音频 .wav 文件,但无济于事。我尝试了几种方法:

File.Copy(My.Resource.click1, "c:\destination folder", True)

我试过调用 Sub
Dim ms As New MemoryStream
My.Resources.click1.CopyTo(ms)
Dim ByteArray() As Byte = ms.ToArray
sfr(toPath2 & "\click1.wav", ByteArray)

Public Sub sfr(ByVal FilePath As Byte, ByVal File As Object)
Dim FByte() As Byte = File
My.Computer.FileSystem.WriteAllBytes(FilePath, FByte, True)
End Sub

我也试过
File.WriteAllText(toPath2 & "\click1.wav", My.Resources.click1)

如何将音频资源复制到硬盘?

最佳答案

这是 tested C# version 的 VB.Net 版本:

Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim file As String = String.Format("{0}.click1.wav", asm.GetName().Name)
Dim fileStream As Stream = asm.GetManifestResourceStream(file)
SaveStreamToFile("c:\Temp\click1.wav", fileStream) '<--here is the call to save to disk


Public Sub SaveStreamToFile(fileFullPath As String, stream As Stream)
If stream.Length = 0 Then
Return
End If

' Create a FileStream object to write a stream to a file
Using fileStream As FileStream = System.IO.File.Create(fileFullPath, CInt(stream.Length))
' Fill the bytes[] array with the stream data
Dim bytesInStream As Byte() = New Byte(stream.Length - 1) {}
stream.Read(bytesInStream, 0, CInt(bytesInStream.Length))

' Use FileStream object to write to the specified file
fileStream.Write(bytesInStream, 0, bytesInStream.Length)
End Using
End Sub

+1 在发布前详细说明您的尝试,让我知道您的进展情况。

关于vb.net - 将音频文件从 Windows 窗体应用程序资源复制到硬盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26310984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com