怎么把结果逐行写入文本文档中
比如每次循环产生一次结果line,只到循环结束就有n多条,那么把这么多条都写入文本中,每条一行,要怎么做 --------------------编程问答-------------------- http://www.cnblogs.com/Excellent/archive/2007/05/23/756397.aspx --------------------编程问答-------------------- StreamWriter.WriterLine(....) --------------------编程问答-------------------- http://msdn.microsoft.com/zh-cn/library/7ack4zyt.aspx --------------------编程问答--------------------这怎么分行啊 --------------------编程问答-------------------- 循环前
if (!System.IO.File.Exists(file))循环中
{
System.IO.FileStream f = System.IO.File.Create(file);
f.Close();
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(file, true, System.Text.Encoding.GetEncoding("gb2312"));
f2.WriteLine(Strings);循环后
f2.Close();--------------------编程问答-------------------- 怎么分行?太乱了、、、 --------------------编程问答-------------------- 每行以"\n\t"结束 --------------------编程问答-------------------- 循环中
f2.Dispose();
f2.WriteLine(line+"\n\t");--------------------编程问答-------------------- 循环拼好在一次写入 或 循环写入
--------------------编程问答--------------------
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));
//把新的内容写到创建的文件中
sw.WriteLine(boby_List);
给个例子自己尝试一下
ArrayList alist = new ArrayList();
string[,] slist = new string[,] {
{ "2012030701", "1", "6201000000000001", "D37571E58820ED73B579F42AF89669AA" },
{ "2012030701", "1", "6201000000000002", "D37571E58820ED73B579F42AF89669AA" },
{ "2012030701", "1", "6201000000000003", "D37571E58820ED73B579F42AF89669AA" },
{ "2012030701", "1", "6201000000000004", "D37571E58820ED73B579F42AF89669AA" }
};
alist.Add(slist);
foreach (string[,] str4 in alist)
{
for (int i = 0; i < str4.GetLength(0); i++)
{
for (int j = 0; j < str4.GetLength(1); j++)
{
StreamWriter sw = File.AppendText("Result.log");
sw.WriteLine(str4[i, j]);
sw.Flush();
sw.Close();
}
}
}
补充:.NET技术 , C#