Using a .txt file Resource in VB

后端 未结 3 1495
野趣味
野趣味 2020-12-10 18:42

Right now i have a line of code, in vb, that calls a text file, like this:

Dim fileReader As String
    fileReader = My.Computer.FileSystem.ReadAllText(\"dat         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 19:16

    I'm assuming that the file is being compiled as an Embedded Resource.

    Embedded Resources aren't files in the filesystem; that code will not work.

    You need to call Assembly.GetManifestResourceStream, like this:

    Dim fileText As String
    Dim a As Assembly = GetType(SomeClass).Assembly
    Using reader As New StreamReader(a.GetManifestResourceStream("MyNamespace.data5.txt"))
        fileText = reader.ReadToEnd()
    End Using
    

提交回复
热议问题