0

ゲームが終了するたびにスコアを保存するためにこれを使用します

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
isf.CreateDirectory("Data");
StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Data\\scoretest.txt", FileMode.Create, isf));
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "                                   Score: " + punc);
sw.Close();

txtから読み取るには、読み取り値がnullになると停止するforを使用します

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
StreamReader sr = null;
try
{
    sr = new StreamReader(new IsolatedStorageFileStream(@"Data\scoretest.txt", FileMode.Open, isf));
    for (;;)
    {
        string x = sr.ReadLine();
        if (x == null)
           break;
        else
            listBox1.Items.Add(x);
    }
    sr.Close();
}
catch
{
    listBox1.Items.Add("");
}

それは最後の行だけを請求します、なぜそれは複数の行を読み取らないのですか?

4

1 に答える 1

2

FileMode.Create は毎回ファイルを上書きします。代わりに FileMode.OpenOrCreate または FileMode.Append を使用する必要があります(参照: http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx )

また、Isolated Storage Explorer ツールを見て、ファイルを確認してください: http://msdn.microsoft.com/en-us/library/hh286408(v=VS.92).aspx

于 2011-09-23T04:49:15.937 に答える