WP7 Application.getResourceStream 每次都返回 null [英] WP7 Application.getResourceStream retunring null every time
问题描述
我正在尝试将 .txt 文件加载到 2D 数组中,我可以从隔离存储中的临时文件中执行此操作,但我们的关卡构建器写入 .txt 文件并将它们移动到每个文件的隔离存储中是不可能的.
Im trying to load a .txt file into a 2D array which i can do from a temp in isolated storage but our level builder writes to .txt files and moving them to isolated storage for each one is out of the question.
这是一个 Windows 手机游戏.
It is a windows phone game.
文本文件构建操作设置为内容.
The text files Build action is set to content.
复制到输出设置为不复制.
The Copy to output is set to Do Not Copy.
该文件位于基本内容文件夹中.
The file is in the base content folder.
var ResrouceStream = Application.GetResourceStream(new Uri("grid_map;component/Data.txt", UriKind.Relative));
if (ResrouceStream != null)
{
//do reading here
}
我在它之后的 if 语句上有一个断点,当我检查 var 时,它仍然为空,稍后通过 using (StreamReader Reader = new StreamReader(ResrouceStream .Stream))代码>
I have a breakpoint on the if statment after it and when i check the var, it is still null and later on it throughs a null error in using (StreamReader Reader = new StreamReader(ResrouceStream .Stream))
因为 ResrouceStream 为空.
because ResrouceStream is null.
我尝试过大多数方法或读取 .txt 文件,但这是最好的方法
Ive tried most ways or reading a .txt file but this seams the best way
推荐答案
如果你想用 Application.GetResourceStream
加载文件,你必须将它的构建动作设置为 Resource
代码>,而不是<代码>内容代码>.
If you want to load the file with Application.GetResourceStream
, you have to set its build action to Resource
, not Content
.
这篇关于WP7 Application.getResourceStream 每次都返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!