在VB中使用.txt文件资源 [英] Using a .txt file Resource in VB
问题描述
现在我在vb中有一行代码,调用了一个文本文件,如下所示:
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("data5.txt")
data5.txt是我的应用程序中的资源,但是该应用程序无法运行,因为它找不到data5.txt.我很确定还有另外一个代码可以在我忽略的资源中查找.txt文件,但是我似乎无法弄清楚.那么有人知道这个简单的解决方法吗?还是另一种全新的代码行?预先感谢!
data5.txt is a resource in my application, however the application doesn't run because it can't find data5.txt. I'm pretty sure there is another code for finding a .txt file in the resource that i'm overlooking, but i can't seem to figure it out. So does anyone know of a simple fix for this? or maybe another whole new line of code? Thanks in advance!
推荐答案
如果在项目+属性"的资源"选项卡中将文件添加为资源,则将使用My.Resources获取其内容:
If you added the file as a resource in the Project + Properties, Resources tab, you'll get its content by using My.Resources:
Dim content As String = My.Resources.data5
单击添加资源"按钮上的箭头,然后选择添加现有文件",然后选择您的data5.txt文件.
Click the arrow on the Add Resource button and select Add Existing File, select your data5.txt file.
这篇关于在VB中使用.txt文件资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!