Adding text to the beginning of a file rather than the end
-
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)
-
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)
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 -
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 KreskowiakIt 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)
-
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)
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
-
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)