vb.net读写资源中的文本文件

vb.net读写资源中的文本文件,vb.net,listbox,resources,Vb.net,Listbox,Resources,我试图用人们可以放入其中的东西制作一个列表,比如购物清单,但我的程序无法访问C:\驱动器,所以我决定将其放入resourcefolder,但这不起作用有人不知道如何让它工作/ 我的代码: Private Sub ThirteenButton14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThirteenButton14.Click ListBox1.Items.Remove(

我试图用人们可以放入其中的东西制作一个列表,比如购物清单,但我的程序无法访问C:\驱动器,所以我决定将其放入resourcefolder,但这不起作用有人不知道如何让它工作/

我的代码:

    Private Sub ThirteenButton14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThirteenButton14.Click
    ListBox1.Items.Remove(ListBox1.SelectedItem)
    Dim i As Integer
    w = New IO.StreamWriter(My.Resources.FavoriteList)
    For i = 0 To ListBox1.Items.Count - 1
        w.WriteLine(ListBox1.Items.Item(i))
    Next
    w.Close()
    ListBox1.Items.Clear()
    R = New IO.StreamReader(My.Resources.FavoriteList)
    While (R.Peek() > -1)
        ListBox1.Items.Add(R.ReadLine)
    End While
    R.Close()
End Sub

Private Sub ThirteenButton13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThirteenButton13.Click
    ListBox1.Items.Add(ThirteenTextBox6.Text + "   |   " + ThirteenTextBox7.Text)
    ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
    Dim i As Integer
    w = New IO.StreamWriter(My.Resources.FavoriteList)
    For i = 0 To ListBox1.Items.Count - 1
        w.WriteLine(ListBox1.Items.Item(i))
    Next
    w.Close()
    ListBox1.Items.Clear()
    R = New IO.StreamReader(My.Resources.FavoriteList)
    While (R.Peek() > -1)
        ListBox1.Items.Add(R.ReadLine)
    End While
    R.Close()
End Sub
这对我不起作用。
如果应用程序没有“资源文件夹”,那么任何帮助都是值得感谢的。您的项目有这样一个文件夹,因为它是存储源项的地方,但资源的全部意义在于它们是编译到EXE本身的数据。因此,它们是只读的。如果您想要一个所有用户都可以安全写入的公共位置,请使用公共文档文件夹

至于您的代码,如果您向资源中添加了一个文件,则该文件的内容将被编译成EXE并通过My.resources返回。运行时没有文件,因此运行时没有文件路径,因此创建StreamReader和StreamWriter的尝试注定会失败。我假设您添加了一个文本文件作为资源。在这种情况下,My.Resources.FavoriteList将以字符串形式返回该文件的内容。您可以使用该数据,但不能对其进行修改并将更改保存回资源,因为该资源是EXE的一部分。

您曾两次说“不工作”,但没有说出“不工作”的含义。它以什么方式不起作用?你很清楚什么不起作用,因为你在这里发帖并这么说。为什么不在你的帖子中与我们分享这些信息呢?我们看不到你的屏幕,也看不懂你的心思。如果您希望我们帮助您,请向我们提供您已经掌握的信息,以便更轻松地进行。如果您遇到错误,请包含*确切的错误消息。如果某件事不起作用,解释它以什么方式不起作用。