【发布时间】:2013-04-24 08:33:08
【问题描述】:
thisoracle java教程中的这句话是什么意思:
如果只有其中一个路径,则无法构造相对路径 包括一个根元素。如果两个路径都包含一个根元素,则 构建相对路径的能力取决于系统。
“系统依赖”是否仅仅意味着如果一个元素包含一个根,它只能在已编写的平台特定语法中工作? 我想这是他们唯一的意思。 还有其他的阅读方式吗?
例如:
public class AnotherOnePathTheDust {
public static void main (String []args)
{
Path p1 = Paths.get("home");
Path p3 = Paths.get("home/sally/bar"); //with "/home/sally/bar" i would get an exception.
// Result is sally/bar
Path p1_to_p3 = p1.relativize(p3);
// Result is ../..
Path p3_to_p1 = p3.relativize(p1);
System.out.println(p3_to_p1); }
}
我使用“/home/sally/bar”而不是“home/sally/bar”(没有root)得到的例外是这个:
java.lang.IllegalArgumentException: 'other' is different type of Path
为什么它不起作用?与系统的冲突是什么意思?
【问题讨论】:
标签: java path relative-path