public File(String pathname) {
if (pathname == null) {
throw new NullPointerException();
}
//将文件路径转为正常状态
this.path = fs.normalize(pathname);
//计算长度的路径字符串前缀,字符串必须是在正常的格式。
this.prefixLength = fs.prefixLength(this.path);
}
//里面操作都一样,就是给两个变量赋值。
public File(File parent, String child)
public File(String parent, String child)
//前面的child为路径,后面的为文件
private File(String child, File parent)
//路径+路径长度
private File(String pathname, int prefixLength)
public File(URI uri) {
// Check our many preconditions
if (!uri.isAbsolute())
throw new IllegalArgumentException("URI is not absolute");
if (uri.isOpaque())
throw new IllegalArgumentException("URI is not hierarchical");
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
if (uri.getAuthority() != null)
throw new IllegalArgumentException("URI has an authority component");
if (uri.getFragment() != null)
throw new IllegalArgumentException("URI has a fragment component");
if (uri.getQuery() != null)
throw new IllegalArgumentException("URI has a query component");
String p = uri.getPath();
if (p.equals(""))
throw new IllegalArgumentException("URI path component is empty");
// Okay, now initialize
p = fs.fromURIPath(p);
if (File.separatorChar != ‘/‘)
p = p.replace(‘/‘, File.separatorChar);
this.path = fs.normalize(p);
this.prefixLength = fs.prefixLength(this.path);
}