java 在线API
java在线APIhttp://www.matools.com/api/java8http://www.matools.com/api/java11
·
jdk 历史版本
java 在线API
http://www.matools.com/api/java8
http://www.matools.com/api/java11
java 7新增的java.nio.file.Files 各种方法中的 Path 参数配合 Paths.get 方法处理
java.nio.file.Files
/**
* This class consists exclusively of static methods that return a {@link Path}
* by converting a path string or {@link URI}.
*
* @since 1.7
*/
public final class Paths {
private Paths() { }
public static Path get(String first, String... more) {
return FileSystems.getDefault().getPath(first, more);
}
public static Path get(URI uri) {
String scheme = uri.getScheme();
if (scheme == null)
throw new IllegalArgumentException("Missing scheme");
// check for default provider to avoid loading of installed providers
if (scheme.equalsIgnoreCase("file"))
return FileSystems.getDefault().provider().getPath(uri);
// try to find provider
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (provider.getScheme().equalsIgnoreCase(scheme)) {
return provider.getPath(uri);
}
}
throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not installed");
}
}
// 文件写入
Files.write(Path path, byte[] bytes, OpenOptions ...options);
//Files.copy(Path from,Path to);
// 文件复制
Path path=Paths.get(“复制的文件路径”);
Path pp=Files.copy(path,Paths.get("复制到的路径"));
//文件写入
Files.write(byte[] bytes, File file)
更多推荐
已为社区贡献2条内容
所有评论(0)