Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. StreamReader and StreamWrite for Text file

StreamReader and StreamWrite for Text file

Scheduled Pinned Locked Moved ASP.NET
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sjs4u
    wrote on last edited by
    #1

    Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs

    C A 2 Replies Last reply
    0
    • S sjs4u

      Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This has nothing to do with ASP.NET. Create a new streamwriter, apparently you can't reopen one you closed.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • S sjs4u

        Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs

        A Offline
        A Offline
        Atif Ali Bhatti
        wrote on last edited by
        #3

        hi, I dont know which framework are u using? but if u r using framework 3.5, I recommed u to use the streamreader and streamwriter objects in using keyword e.g., using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("Reading"); } using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { Console.WriteLine(sr.ReadLine()); } } Hope this helps. Regards, Atif Ali Bhatti.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups