In C#, is there a way to add an XML node to a file on disk WITHOUT loading it first?

前端 未结 8 1989
后悔当初
后悔当初 2020-12-20 14:14

I have a very basic XML structure/file on disk which is something like:


    kdkdkdk         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 14:42

    Depends.

    If you want to do it the "correct" way, you have to read the file and the XML in it. You can avoid loading it completely into memory by using an XmlReader class for example.

    However, if you definitely absolutely know the text-layout and the encoding of the file, you can avoid reading and re-writing it completely by opening it as random-access file (FileStream), skip to the end (minus the ""), add the new entry there and write the "" again.

提交回复
热议问题