且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文件处理,替换文本文件中的特定行

更新时间:2023-01-15 17:48:33

使用此代码,这可能对您有帮助

use this code , this may helps you

//Read all lines from the file
string[] data=File.ReadAllLines("myfile.txt");
//replace the first line with your data.
 data[0] = "my own text";
//write all data again into the file.
 File.WriteAllLines("myfileout.txt", data);



谢谢
--RA



Thanks
--RA


string[] lines = File.ReadAllLines("file.txt");

lines[0]="New Line to overwrite";

File.WriteAllLines("file.txt", lines );