【发布时间】:2016-01-04 00:38:40
【问题描述】:
我正在尝试读取名为 thedata.txt 的文本文件,其中包含我想在刽子手游戏中使用的单词列表。我尝试了不同的方法,但我无法确定文件的放置位置,如果在应用程序运行时根本无法确定的话。我将文件添加到我的项目中,我尝试将构建属性设置为内容,然后嵌入资源,但找不到文件。我制作了一个 Windows 10 通用应用程序项目。我试过的代码是这样的:
Stream stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("thedata.txt");
using (StreamReader inputStream = new StreamReader(stream))
{
while (inputStream.Peek() >= 0)
{
Debug.WriteLine("the line is ", inputStream.ReadLine());
}
}
我得到了例外。 我还尝试列出另一个目录中的文件:
string path = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
Debug.WriteLine("The path is " + path);
IReadOnlyCollection<StorageFile> files = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync();
foreach (StorageFile file2 in files)
{
Debug.WriteLine("Name 2 is " + file2.Name + ", " + file2.DateCreated);
}
我在那里也看不到文件...我想避免在我的程序中对名称列表进行硬编码。我不确定该文件的放置路径。
【问题讨论】:
标签: c# windows-10-universal windows-10-mobile