解决方案 »

  1.   

    不好意思 ,code中的<span style="color: #FF0000;">等标签是我点击字体颜色时不小心弄的,这个不在代码里面,请忽略它
      

  2.   

    new File(file.list()[0]
    红色这个返回的 是文件的名称不含路径  。
      

  3.   

    这我知道啊,但这就是问题所在啊,new File(file.list()[0]) 返回的是0.txt,为什么后面的getAbsolutePath()方法返回的是那样的路径啊,不应该是d:\dir\0.txt吗,为什么是E:\eclipse workingspace\summer vacation study\0.txt,我就是这一点没懂啊,求赐教啊!!!
      

  4.   

    file.list()[0] 返回的是文件名,不包括前面路径,用这个创建新的File,其相对路径是System.getProperty("user.dir")
      

  5.   

    /**
         * Returns the absolute pathname string of this abstract pathname.
         *
         * <p> If this abstract pathname is already absolute, then the pathname
         * string is simply returned as if by the <code>{@link #getPath}</code>
         * method.  If this abstract pathname is the empty abstract pathname then
         * the pathname string of the current user directory, which is named by the
         * system property <code>user.dir</code>, is returned.
      Otherwise this
         * pathname is resolved in a system-dependent way.  On UNIX systems, a
         * relative pathname is made absolute by resolving it against the current
         * user directory.  On Microsoft Windows systems, a relative pathname is made absolute
         * by resolving it against the current directory of the drive named by the
         * pathname, if any; if not, it is resolved against the current user
         * directory.
         *
         * @return  The absolute pathname string denoting the same file or
         *          directory as this abstract pathname
         *
         * @throws  SecurityException
         *          If a required system property value cannot be accessed.
         *
         * @see     java.io.File#isAbsolute()
         */
        public String getAbsolutePath() {
    return fs.resolve(this);
        }
      

  6.   

    rui888是正解,如果期望得到你预期的结果,可以这样修改一下:
    // file.list()[0]取到的是文件名,"0.txt"
    File file2 = Paths.get(filePath, file.list()[0]).toFile();  // 这里可以得到你想要的文件d:\dir\0.txt
    System.out.println(file2.getAbsolutePath()); 
      

  7.   

    谢谢!哦了
    thanks very much!!!!