|
-
May 30th, 2003, 01:18 AM
#1
Thread Starter
Member
File Handling
er ... how do I open a exsit file and write extra string into any line(s) in the original file
like say the original file is
ABCDHIJKLMN...
and i wanna insert EFG into ABCD and HIJ...
what should i do? :s
-
May 30th, 2003, 09:42 AM
#2
PowerPoster
I haven't done this, but you are going to want to look into streams. Maybe TextWriter and TextReader streams?..?
Not sure, good luck.
-
May 30th, 2003, 12:01 PM
#3
I played around for you, and I couldn't get it to insert data, just overwrite...
Code:
// C:\text.txt contains "ABCDEFGMNOPQRSTUVWXYZ"
FileStream f = new FileStream("C:\\text.txt", FileMode.Open , FileAccess.ReadWrite);
while(f.ReadByte() != 'G')
{
}
f.WriteByte((byte)'H');
f.WriteByte((byte)'I');
f.WriteByte((byte)'J');
f.WriteByte((byte)'K');
f.WriteByte((byte)'L');
f.Close();
// C:\text.txt contains "ABCDEFGHIJKLRSTUVWXYZ"
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Jun 3rd, 2003, 06:14 AM
#4
I fear it can't be done. You must read in everything after the location where you want to insert, then write out what you want to insert and then the rest of the file.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|