Write to a embedded text file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Barda4
    New Member
    • Jan 2009
    • 5

    Write to a embedded text file?

    Hi,
    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.
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    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.

    Comment

    • Barda4
      New Member
      • Jan 2009
      • 5

      #3
      Code I am using

      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 _textStreamRead er;

      Here is the code I read with :
      try
      {
      _assembly = Assembly.GetExe cutingAssembly( );
      _textStreamRead er = new StreamReader(_a ssembly.GetMani festResourceStr eam("WindowsApp lication2.Resou rces.Stats.txt" ));
      }
      catch
      {
      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."

      Comment

      • nukefusion
        Recognized Expert New Member
        • Mar 2008
        • 221

        #4
        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).

        Comment

        • Barda4
          New Member
          • Jan 2009
          • 5

          #5
          Thanks for replying

          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.

          Comment

          Working...