Q:

How to insert a new line in a text file without deleting or overwriting data in same line and without having second file in C#?

I want to add few lines in the middle of text file without overwriting or deleting  existing data already in text file. For example:
Before insertion of new line
ABCD1A_GNHM_MODL_LEWLA  
ABCD12A_GGHM_MODL_LEWLA   
ABCD13A_GEHM_MODL_LEWLA     
ABCD14A_GHHM_MODL_LEWLA     
ABCD12A_GGHM_MODL_LEWLA  
ABCD1AW_GVHM_MODL_LEWLA       
ABCD1R_GGHB_MODL_LEWLA   
ABCD1R_GCHM_MODL_LEWLA  

After insertion of new lines
ABCD1A_GNHM_MODL_LEWLA    
ABCD12A_GGHM_MODL_LEWLA  
ABCD13A_GEHM_MODL_LEWLA      
ABCD14A_GHHM_MODL_LEWLA     
AAAAAAA_VVVV_vVVVV_vvVV9  ---- THIS LINE IS INSERTED  
AAEEEE_VVVV_vVVVV_vvVV9   ------THIS LINE IS INSERTED  
ABCD12A_GGHM_MODL_LEWLA  
ABCD1AW_GVHM_MODL_LEWLA     
ABCD1R_GGHB_MODL_LEWLA   
ABCD1R_GCHM_MODL_LEWLA  

For tracing after which line i need to insert data is depended on requirement as of now consider after 4th line I need to insert two lines.
Can any one suggest me how to do it?

A:

This boils down to the way files work. There simply isn't any other way than writing the remainder of the file all again, which is going to be costly, if it's a long file. Only appending to the end is relatively cheap.
And don't forget, that the file on disk doesn't care about endlines - we're talking bytes here, not a collection of strings.
Your best bet will probably be to create a whole new file, copy the data before insert there first, then add your data, and then continuing the copying of the rest of the file.
Short story: You can't insert anything in the middle of a file. You'll always overwrite. You have to write at least all the bytes from the insert location forward.

