日期:2014-05-18 浏览次数:21011 次
string path1 = Directory.GetCurrentDirectory();
using (StreamWriter sw = File.CreateText(path1+@"\wulin\wulin.map"))
{
sw.WriteLine("hello");
sw.WriteLine("你好");
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("hello");
sb.AppendLine("你好");
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() != DialogResult.OK)
{
MessageBox.Show("没有选文件来保存!","提示");
return;
}
string fileName = sfd.FileName;
if (File.Exists(fileName))
{
if (MessageBox.Show("文件已存在,覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.WriteAllText(fileName, sb.ToString(), Encoding.UTF8);
MessageBox.Show("保存成功。", "提示");
}
else
{
MessageBox.Show("你选择不覆盖!没有保存。", "提示");
}
}
else {
File.WriteAllText(fileName, sb.ToString(), Encoding.UTF8);
MessageBox.Show("保存成功。", "提示");
}