如何将文本一行行写入dat文件

fangpengyu 2010-09-07 03:34:40
现在需要将一行一行的文本写入到dat文件,每写一行要换行,要写入的数据是从数据库取出的,
dat文件时自己生成的,还请帮忙,最好有code,谢谢!
...全文
433 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yutian_31 2010-09-07
  • 打赏
  • 举报
回复
留个脚印,么事看看
ajq1989 2010-09-07
  • 打赏
  • 举报
回复
更 读取记事本是一样的 。


//生成批处理文件用于重启程序
string bat=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"update.bat");
if (File.Exists(bat))
File.Delete(bat);
using(StreamWriter sw=new StreamWriter(bat,true))
{
sw.WriteLine("@echo off");
sw.WriteLine(":find");
FileInfo appexe = new FileInfo(Application.ExecutablePath);
sw.WriteLine(string.Format("tasklist|find \"{0}\" ||goto next", appexe.Name));
sw.WriteLine("goto find");
sw.WriteLine(":next");
foreach (string name in okfiles)
{
sw.WriteLine(string.Format("copy update\\{0} {1} /y",name,name));
}
sw.WriteLine("start "+Application.ExecutablePath);
sw.WriteLine("del %0");
sw.WriteLine("exit");
}
System.Diagnostics.Process.Start(bat);
Environment.Exit(0);
wzlblair 2010-09-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
File.AppendText
File.WriteAllLines
StreamWriter
[/Quote]
liuyilin888 2010-09-07
  • 打赏
  • 举报
回复
WriteLine
wuyq11 2010-09-07
  • 打赏
  • 举报
回复
File.AppendText
File.WriteAllLines
StreamWriter
guyehanxinlei 2010-09-07
  • 打赏
  • 举报
回复

System.IO.StreamWriter sw = null;
try
{
sw = new System.IO.StreamWriter(@"d:\data.dat", true);
for (int i = 0; i < 10; i++)
{
sw.WriteLine(String.Format("Item {0}.", i));
}
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{

sw.Close();
sw.Dispose();
}

110,533

社区成员

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

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

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