Microsoft.Xna.Framework.TitleContainer.OpenStream()

/// <summary>
/// This method opens a file using System.IO classes and the
/// TitleLocation property. It presumes that a file named
/// ship.dds has been deployed alongside the game.
/// </summary>
private static void DoOpenFile()
{
    try
    {
         System.IO.Stream stream = TitleContainer.OpenStream("aa.txt");
         System.IO.StreamReader sreader = new System.IO.StreamReader(stream);
        // use StreamReader.ReadLine or other methods to read the file data

        Console.WriteLine("File Size: " + stream.Length);
        stream.Close();
    }
    catch (System.IO.FileNotFoundException)
    {
         // this will be thrown by OpenStream if gamedata.txt
        // doesn't exist in the title storage location
     }
}

posted @ 2014-09-24 21:57  秋月光璇LMQ  阅读(243)  评论(0编辑  收藏  举报