在给定行写入文本文件 [英] Writing to a text file at a given line
本文介绍了在给定行写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我知道如何使用以下代码编写文本文件.但是它在第一行添加了给定的文本.如果我想在特定的行上写而不影响其上一行,该怎么办?
非常感谢您
Hello,
I know how to write in a text file using the code below. But it adds the given text at the first line. If I want to write at a specific line without affecting its upper lines, what should I do?
Thank you very much
try
{
using (StreamWriter sw = new StreamWriter @"E:\Hello.txt"))
{
sw.Write(textBox1.Text);
}
}
catch
{
MessageBox.Show("Writing failed");
}
推荐答案
使用StreamWriter.BaseStream.Seek
方法
这篇关于在给定行写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文