且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何动态命名文件名

更新时间:2021-11-16 09:19:43

问题是在完成所有记录处理之前你不知道名字。

我要做的是:

1)将文件数据组装到List中并在结尾处一次写入。这时你知道文件名应该是什么。



2)将文件写入临时文件,然后在关闭文件后使用File.Move更改名称。



处理完所有记录后,计算出文件名是微不足道的。
The problem is that you don't know the name until you have finished processing all teh records.
What I would do is either:
1) Assemble the file data into a List and write it all at once at the end. By this time you know what the file name should be.
Or
2) Write the file to a temporary file, and then use File.Move to change it's name at the end, once I'd closed it.

Once you have all the records processed, working out the file name is trivial.