/** * 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); }
红色这个返回的 是文件的名称不含路径 。
* 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);
}
// file.list()[0]取到的是文件名,"0.txt"
File file2 = Paths.get(filePath, file.list()[0]).toFile(); // 这里可以得到你想要的文件d:\dir\0.txt
System.out.println(file2.getAbsolutePath());
thanks very much!!!!