当尝试写入文件名“aux”的路径时,我很困惑地收到异常。同一目录和不同目录中的其他文件名都可以正常工作,我以前从未遇到过这种麻烦。
为了给您一个想法,请考虑以下测试代码:
Directory.CreateDirectory ("D:\\asdf"); // OK
File.WriteAllText ("D:\\asdf\\aux_", ""); // OK
try {
File.WriteAllText ("D:\\asdf\\aux.txt", ""); // fails
}
catch (ArgumentException ex) {
Console.WriteLine (ex);
}
try {
File.WriteAllText ("D:\\asdf\\aux", ""); // fails
}
catch (ArgumentException ex) {
Console.WriteLine (ex);
}
Console.WriteLine (string.Join ("\n", Directory.EnumerateFiles ("D:\\asdf")));
Run Code Online (Sandbox Code Playgroud)
最后一行打印创建了一个文件:
D:\asdf\aux_
Run Code Online (Sandbox Code Playgroud)
抛出两个相同的异常:
System.ArgumentException: FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path.
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean …Run Code Online (Sandbox Code Playgroud)