敲了一段修改压缩文件内容的代码,如下:
public static void rarWriteTest() {
Path tempRar = Paths.get("D:\\copy.rar");
try (FileSystem workingFs =
FileSystems.newFileSystem(tempRar, null)) {
Path pathForFile = workingFs.getPath("/hello.txt");
List ls = new ArrayList<>();
ls.add("Hello World!");
Files.write(pathForFile, ls, Charset.defaultCharset(),
StandardOpenOption.WRITE, StandardOpenOption.CREATE);
}
catch (IOException e) {
e.printStackTrace();
}
}
运行报如下错:
Exception in thread "main" java.nio.file.ProviderNotFoundException: Provider not found
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:407)
at io.StaticDemos.rarWriteTest(StaticDemos.java:43)
at io.StaticDemos.main(StaticDemos.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
查了一下api,api这样写:
ProviderNotFoundException - if a provider supporting this file type cannot be located
然而并不明白啊,provider究竟是啥?