@Fox9 wrote:
I'm using this code in my iOS project to load text files and it's working. But on Android the code isn't working. I want to load a text file(File.txt) but I get this error message. I set the build action of File.txt to "Content". The file is located in my Android project's directory.
System.IO.Stream stream = TitleContainer.OpenStream(filename);
System.IO.FileNotFoundException has been thrown File.txt
How can I load the text file on Android?
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System.IO; using System.IO.IsolatedStorage; namespace Androidproject.Android { public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; private static System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("de-DE"); private const string filename = "File.txt"; string[] strs; public void LoadFile() { System.IO.Stream stream = TitleContainer.OpenStream(filename); using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); strs = line.Split(';'); } } } public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.IsFullScreen = true; graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 480; graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); LoadFile(); } protected override void Update(GameTime gameTime) { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } } }
Posts: 1
Participants: 1