By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

Write to a embedded text file?

P: 5
I am trying to make a game, where the player can save their stats. So far I've got it so the text file can be read, so loading the game, but I cannot figure out out how write to the text file, so saving the game. I have tried changing the code of StreamRead to StreamWrite, but it comes up with an error.
Jan 31 '09 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 221
It might be helpful if you post exact details of the error that occurs and maybe a snippet of your code so that we can see where exactly it is going wrong.
Jan 31 '09 #2

P: 5
Thanks for answer, I've tried like 3 other websites and not even a reply!

Ok so here is the code I declare publicly :

Assembly _assembly;
StreamReader _textStreamReader;

Here is the code I read with :
_assembly = Assembly.GetExecutingAssembly();
_textStreamReader = new StreamReader(_assembly.GetManifestResourceStream(" WindowsApplication2.Resources.Stats.txt"));
MessageBox.Show("Error accessing resources!");

That works fine, but if I try and change the StreamReader to StreamWriter, I get an error saying "Stream not writable."
Jan 31 '09 #3

Expert 100+
P: 221
Okay, thanks for posting the sample code as now I can see what you are trying to do.

You're trying to write to a text file that is embedded inside your assembly and that is why you are getting an error. To avoid this you should create the text file as a separate resource (not embedded within your assembly).
Jan 31 '09 #4

P: 5
Thanks for replying. Well I guess that means I am gonna have to do some changes :/. But thanks for the answer, cause if u didn't tell me I would have probably spend forever trying to fix the problem.
Feb 1 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.