Writing a File that has the Name of a Device

后端 未结 2 939
猫巷女王i
猫巷女王i 2021-01-12 02:32

I have run into something curious. I have a decompiler that extracts information from a binary file. I am extracting a series of objects that I need to write separately to

2条回答
  •  一个人的身影
    2021-01-12 02:56

    Wrap the call to "new FileStream" with a try/catch block to specifically catch System.ArgumentException. If you catch this, assume the the filename is invalid and try again with a different filename (e.g. prepend "foo" to the filename string).

    Also, you can use System.IO.Path.GetInvalidPathChars() and System.IO.Path.GetInvalidFileNameChars(); to get the complete list of "invalid characters" that won't fit inside a windows filename. So you can strip out or replace those chars fromthe filename string before attempting to create the file.

提交回复
热议问题