为什么这种方法设计为考虑单个 \ 一个根?
因为就其他操作而言,它是根。例如,在命令提示符下:
c:\Users\Jon\Test>dir \
Volume in drive C is Windows8_OS
Volume Serial Number is C058-6ADE
Directory of c:\
或者来自 .NET 中的其他文件操作:
using System;
using System.IO;
class Test
{
static void Main()
{
var lines = File.ReadAllLines(@"\Users\Jon\Test\Test.cs");
Console.WriteLine(lines.Length);
}
}
输出:
11
或来自 Java:
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
String path = "\\Users\\Jon\\Test\\Test.java";
// Just to prove that the double backslashes are language escapes...
System.out.println(path);
// Obviously we'd normally clean stuff up...
InputStream stream = new FileInputStream(path);
BufferedReader reader = new BufferedReader
(new InputStreamReader(stream, "utf-8"));
System.out.println(reader.readLine());
}
}
输出:
\Users\Jon\Test\Test.java
import java.io.*;
我敢说本机代码也是如此。
那么,Windows 哪里不允许您以“\”开头的路径在当前驱动器中对其进行根目录?
为什么这种方法设计为考虑单个 \ 一个根?
我认为更大的问题是为什么你开始了你想要的相对路径\。