【发布时间】:2012-11-26 16:24:19
【问题描述】:
我正在开发一款 windows phone 7 游戏,我已将关卡保存在文本文件中,我想将其加载到二维数组中,但没有 txt 文件的内容导入器,我使用了隔离存储管理器
protected void read_lvl()
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{ //Visualize the text data in a TextBlock text
while (!reader.EndOfStream)
{
//for each row
for (int i = 0; i < rows; i++)
{
//read in the line
string myLine = reader.ReadLine();
//take out the commas
string[] row = myLine.Split(',');
//convert to string to ints
//and feed back into array
int[] nRow = new int[row.Length];
for(int r=0; r<columns;r++){
nRow[r] =Convert.ToInt32(row[r]);
myreadArray[i, r] = nRow[r];
}
}
}
}
}
这对于加载保存的游戏状态等很好
但我想在多个.txt 文件中有多个级别,并尝试使用它来代替:
//stream from file
Stream stream = TitleContainer.OpenStream("myFile.txt");
//make a stream reader from the stream
using (StreamReader sreader = new StreamReader(stream))
但是它抛出了同样的错误:没有处理这种文件类型的进口商。
做什么?
【问题讨论】:
标签: c# windows-phone-7 xna-4.0 filereader