import java.nio.file.*;class Test
{
          public static void main(String[] args) 
          {
              Path p=Paths.get(".");
              System.out.println(p.getNameCount());          
         
          }
}
如果你把“.”换成当前路径,再运行一遍发现结果不一致。
应该不是bug,但JAVA究竟是如何处理和看待这个“.”东东的??API Specifications follow below:int getNameCount()Returns the number of name elements in the path.Returns:
    the number of elements in the path, or 0 if this path only represents a root component

解决方案 »

  1.   

    这个貌似是具体路径没有什么关系吧,应该与JAVA对待“."或”.."的方式有关。
      

  2.   

    你用Ide的话可以断点path ,.应该是表示当前运行的class 文件位置的
      

  3.   

    你用Ide的话可以断点path ,.应该是表示当前运行的class 文件位置的
      

  4.   

    你用Ide的话可以断点path ,.应该是表示当前运行的class 文件位置的
      

  5.   

    可以通过这个看一下结果不一致的两次Path代表的路径各自是什么,尤其是"."
    System.out.format("toString: %s%n", p.toString());
      

  6.   

    这尼玛真是个bug.....
    "."在path类型中没翻译成本地绝对路径, 导致count=1plus: getNameCount()这个函数不好, "C:\\a\\"是1, "C:\\a\\."是2, 在C:\\a\\目录下, "."是1
      

  7.   

    本来就是这么设计的吧……
    要翻译成绝对路径,请调用toAbsolutePath这个方法
      

  8.   

    "." 相对于虚拟机的当前目录。 一般是 %JAVA_HOME%/bin