FileStream Append Data at the top

后端 未结 3 1271
南笙
南笙 2021-01-23 09:10

I am working on a utility.

I want to append data at the top of the file, but it is overwritting not appending.

For eg : Consider the file.txt :

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 09:45

    Yes

    FileStream fs = new FileStream( path2, FileMode.OpenOrCreate, FileAccess.ReadWrite );

    sw = new StreamWriter( fs );

    sw.BaseStream.Seek( 0, 0 );

    sw.WriteLine( "write new text" );

    sw.close()

    This method will overwrite any existing data, akin insert and replace.

提交回复
热议问题