C#在.txt文件中最后一个字符后面直接写入数据应该用什么方法

别闹了费曼sir 2016-05-31 10:20:36
用StreamWriter中Write()与WriteLine()方法都是另起一行开始写入,想直接在最后一个字符后写入,不用另起一行,用什么方法?
...全文
430 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
songbing774933 2016-06-01
  • 打赏
  • 举报
回复
很多方法:
1. 使用 File.AppendAllText 函数
2.使用FileStream,并设置fs.Position = fs.Length;
3.使用StreamWriter
public StreamWriter(string path , bool append);
public StreamWriter(string path , bool append , Encoding encoding);
public StreamWriter(string path , bool append , Encoding encoding , int bufferSize);
失落的神庙 2016-06-01
  • 打赏
  • 举报
回复
 
   StreamWriter sw = new StreamWriter("a.txt", true, Encoding.UTF8);
            sw.Write("xxxxx");
            sw.Close();


Justin-Liu 2016-06-01
  • 打赏
  • 举报
回复
用Write
mlxwl2013 2016-05-31
  • 打赏
  • 举报
回复
直接用File.AppendAllText("文件名","数据");
Poopaye 2016-05-31
  • 打赏
  • 举报
回复
说明txt最后一个字符就是换行符,不管用什么方法你看到的都是另起一行

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧