how to insert row in first line of text file?

前端 未结 6 1661
星月不相逢
星月不相逢 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条回答
  •  一向
    一向 (楼主)
    2020-12-09 19:00

    @Jake: StringBuilder is better and easiest

    public static void WriteToFile(string path, string text)
    {
            StringBuilder stringBuilder = new StringBuilder();
    
            stringBuilder.AppendLine("a,b,c");
            stringBuilder.Append(File.ReadAllText(path)).AppendLine();
            File.WriteAllText(path, stringBuilder.ToString()); 
    }
    

    Edit: But StringBuilder has a buffer limit: Maximum Capacity 2147483647

提交回复
热议问题