是否可以新建无名的文件?
我想新建一个文件,但不知道是否可以实现新建的文件时没有名称的
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("保存成功。", "提示");}