how to insert row in first line of text file?

前端 未结 6 1669
星月不相逢
星月不相逢 2020-12-09 18:38

I have a test file that contains

1,2,3
2,3,4
5,6,7

I want to insert this into the first line: A,B,C

So that I get:

6条回答
  •  猫巷女王i
    2020-12-09 19:02

    I think this answer is easier and faster:

    public static void WriteToFile(string Path, string Text)
    {
        string content = File.ReadAllText(Path);
        content = Text + "\n" + content;      
        File.WriteAllText(Path, content);
    }
    

    Then you can call it:

    WriteToFile("yourfilepath", "A,B,C");
    

提交回复
热议问题