C#应用下的txt文件写入
方法如下:
//file storage function
public bool txt_file_generate(Dictionary<int, string> dic_val)
{
FolderBrowserDialog my_diaglog = new FolderBrowserDialog();
string save_path = string.Empty;
bool save_ok;
string val = null;
string file_name = DateTime.Now.ToString("yyyyMMddHHmmss") + "_Accurtestlogs.txt";
if (my_diaglog.ShowDialog() == DialogResult.OK)
{
save_path = my_diaglog.SelectedPath + "\\" + file_name;
}
FileStream fs = new FileStream(save_path, FileMode.Append);
StreamWriter sw = null;
sw = new StreamWriter(fs);
foreach (KeyValuePair<int, string> pair in dic_val)
{
sw.WriteLine(pair.Value);
}
sw.Close();
fs.Close();
save_ok = true;
return save_ok;
}