Cross-platform file name handling in .NET Core

前端 未结 6 1409
我在风中等你
我在风中等你 2020-12-15 03:02

How to handle file name in System.IO classes in a cross-platform manner to make it work on Windows and Linux?

For example, I write this code that works

6条回答
  •  执念已碎
    2020-12-15 03:27

    Of course forward slashes work fine - except when they don't. It is an older problem, but certainly LoadLibrary actually bit me in this regard. Please see https://stackoverflow.com/a/34708551/1318024 which discusses this. Even though we do expect Windows to handle path separators gracefully (which we do not expect for *nix!) it is best to use the path separator appropriate for the platform.

提交回复
热议问题