我看了前面的这个问题,但是这个问题似乎不适用于Windows phone7项目的XNA4:XNA Framework Importers
我一直在尝试使用:
string line;
using (StreamReader sr = new StreamReader("credits.txt"))
{
while ((line = sr.ReadLine()) != null)
{
//reads line by line until eof
//do whatever you want with the text
}
}`
但这抛出了一个System.MethodAccessException“尝试访问方法失败: System.IO.StreamReader..ctor(System.String)”
为此,我需要考虑使用IsolatedStorage吗?
编辑:请注意,我正在尝试加载一个预先准备好的文件,而不是保存正在运行的应用程序的设置。例如,一个包含片头的文本文件,我只会在运行时读入,但需要在设计时能够编辑。
发布于 2010-09-19 07:37:15
找到了;我不需要IsolatedStorage也能做到,只需要使用一个结构如下的XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="System.String">
<credit>
Firece Game Hunting
Developer : Sebastian Gray
Deer (CC) : Martin Pettitt
http://www.flickr.com/photos/mdpettitt
</credit>
</Asset>
</XnaContent>然后加载XML文件,如下所示:
public string LoadFromFile()
{
using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create("XMLFile1.xml"))
{
reader.MoveToContent();
reader.ReadToFollowing("credit");
credits = reader.ReadInnerXml();
}
return credits;
}可以将XML文件添加到普通项目(而不是内容项目)中,并将构建操作设置为“内容”,将“复制到输出目录”设置为“始终复制”。
发布于 2010-09-19 06:38:54
我是否需要考虑使用IsolatedStorage来实现此目的?
是的,每个应用程序(操作系统应用程序除外)都需要使用IsolatedStorage将数据存储在物理内存中,或者您可以使用可能的服务来存储数据。
IsolatedStorage example
发布于 2010-09-19 07:37:30
为什么不直接写一个内容管道扩展,让内容管理器来操心呢?这其实很简单。This MSDN article explains how。
Here's a blog post给出了一个很好的高级概述。
https://stackoverflow.com/questions/3743722
复制相似问题