how to insert row in first line of text file?

前端 未结 6 1668
星月不相逢
星月不相逢 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 18:49

    Here is a link that explains how to use the TextReader (StreamReader) and TextWriter (StreamWriter) classes in C#.

    http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=132

    Though this is specific to C#, the approach could be relatively the same across many languages.

    (Note: There are several ways to do this, this is just one idea that comes quickly to mind.)

    Essentially, you could read in the contents of your text file into a string, find the beginning of that string, write your information (A,B,C with your carriage returns or line feeds) and then write that information back out into the text file overwriting the original contents and save.

提交回复
热议问题