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
     }
}

原文地址:https://www.cnblogs.com/qiuyueguangxuan/p/3991634.html