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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Adding text to the beginning of a file rather than the end

Adding text to the beginning of a file rather than the end

Scheduled Pinned Locked Moved Visual Basic
performancetutorialquestion
5 Posts 4 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.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not. What I want to do is add some data to the beginning of a file without reading and writing the entire file. The files are large text files, a lot of the time they are gigabytes in size so it is inefficient and most of the time not possible to read it into memory and manipulate the data. Is there an option through a FileStream or some other type of I/O class that will open a file allow me to point to the beginning and write text as an "insert" type of operation and save the file? An example of what I am trying to do is below. Start Middle End Open file and add to the beginning New Text Start Middle End


    CleaKO

    "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

    D L L 3 Replies Last reply
    0
    • M Marcus J Smith

      I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not. What I want to do is add some data to the beginning of a file without reading and writing the entire file. The files are large text files, a lot of the time they are gigabytes in size so it is inefficient and most of the time not possible to read it into memory and manipulate the data. Is there an option through a FileStream or some other type of I/O class that will open a file allow me to point to the beginning and write text as an "insert" type of operation and save the file? An example of what I am trying to do is below. Start Middle End Open file and add to the beginning New Text Start Middle End


      CleaKO

      "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      CleaKO wrote:

      I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not.

      Yes, it's still true, until someone creates an entirely new file system that supports writing at either end of a file instead of just the end.

      CleaKO wrote:

      What I want to do is add some data to the beginning of a file without reading and writing the entire file.

      Can't be done. The only way to prep for an operation like that would be to pad the beginning of the file to save room for writing from the beginning of the actual content of the file.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        CleaKO wrote:

        I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not.

        Yes, it's still true, until someone creates an entirely new file system that supports writing at either end of a file instead of just the end.

        CleaKO wrote:

        What I want to do is add some data to the beginning of a file without reading and writing the entire file.

        Can't be done. The only way to prep for an operation like that would be to pad the beginning of the file to save room for writing from the beginning of the actual content of the file.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        It was your reply that I found earlier, :). Thanks for confirming.


        CleaKO

        "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

        1 Reply Last reply
        0
        • M Marcus J Smith

          I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not. What I want to do is add some data to the beginning of a file without reading and writing the entire file. The files are large text files, a lot of the time they are gigabytes in size so it is inefficient and most of the time not possible to read it into memory and manipulate the data. Is there an option through a FileStream or some other type of I/O class that will open a file allow me to point to the beginning and write text as an "insert" type of operation and save the file? An example of what I am trying to do is below. Start Middle End Open file and add to the beginning New Text Start Middle End


          CleaKO

          "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          If you feel a need to do that, it should tell you huge text files are not the right approach. If your data would reside in a series of files, with some particular order imposed (maybe alphabetically sorted file names), then you could insert at the beginning, at the end, and at each file switching point, simply by adding one more file with the appropriate characteristics (e.g. filename) that make it sit where it belongs. :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          1 Reply Last reply
          0
          • M Marcus J Smith

            I just found a message from 2004 that said there is no option for opening a file and adding text to the beginning. I want to validate whether that is still true or not. What I want to do is add some data to the beginning of a file without reading and writing the entire file. The files are large text files, a lot of the time they are gigabytes in size so it is inefficient and most of the time not possible to read it into memory and manipulate the data. Is there an option through a FileStream or some other type of I/O class that will open a file allow me to point to the beginning and write text as an "insert" type of operation and save the file? An example of what I am trying to do is below. Start Middle End Open file and add to the beginning New Text Start Middle End


            CleaKO

            "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Writing a file isn't an "insert operation". It's modifying what's there, or writing beyond it's limits if there's room. --edit; Just reread Luc's post :thumbsup:

            Bastard Programmer from Hell :suss:

            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