详情:
抛出异常System.NotSupportedException:“不支持给定路径的格式。”,
抛出异常位置:创建文件流,
运行时fileName的值为:"201829815:14:33591.txt"。
注释掉的代码部分是我尝试的解决办法,但抛出相同异常。
请不吝赐教,谢谢!FileStream的
官方帮助文档https://docs.microsoft.com/zh-cn/dotnet/api/system.io.filestream?view=netframework-4.7.2
//路径定义
/*string currPath = Application.StartupPath;*/
string fileName =/*currPath+*/DateTime.Now.Year.ToString() +
DateTime.Now.DayOfYear.ToString() +
DateTime.Now.ToLongTimeString() +
DateTime.Now.Millisecond.ToString()+".txt";
//创建文件流
FileStream fs = new FileStream(fileName, FileMode.CreateNew);
//创建写入器
StreamWriter streamWriter = new StreamWriter(fs);
for (int i = 0; i < listBox1.Items.Count; i++)
{
streamWriter.Write(listBox1.Items[i]);
}
//关闭写入器
streamWriter.Close();
//关闭文件流
fs.Close();
//显示打印结果
MessageBox.Show("打印成功", "打印结果");