java的provider,java,_Java里的Provider是什么?,java - phpStudy

Java里的Provider是什么?

敲了一段修改压缩文件内容的代码,如下:

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究竟是啥?

相关阅读:

tabview和scrollview嵌套问题

Android 静态常量对象什么时候被回收?

iOS开发一些问题

SQL查询语句

正则匹配字符串并跳过指定字符串

如何让Canvas标签自适应设备宽度?

支持IE6的图片轮播插件

上传图片后服务器返回的url 的缓存问题

微信开放平台创建的移动应用使用微信支付时怎么设置回调url?

angular.js中一组复选框,怎么实现选中其中一个,其他不能选?

360、手机管家在iOS端的后台模式选择什么 上传到AppStore时应注意什么

RecyclerView 莫名奇妙自动滚动的问题

为什么这样编码没效果?

promise如何返回最快执行完的请求

判断某个字符串是否存在,是reg.test快还是str.indexOf快?

如何将Speex编译为供JNI调用的dll文件?

A星寻路算法怎么应用于不规则 地图 如梦幻西游 ?

vue 2.0 的入门和文档从哪里看?

php 如何解析这样一个xml文件?

模型B中有外键联系到模型A,通过什么样的 ORM 查询语句能够过滤A表中的数据在 B 中有或者没有记录的 ?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先需要定义一个树结构的节点类,包含节点值和子节点列表: ```java class TreeNode { int val; List<TreeNode> children; public TreeNode(int val) { this.val = val; children = new ArrayList<>(); } } ``` 然后可以实现树的遍历方法,比如先序遍历: ```java public void preOrder(TreeNode root) { if (root == null) { return; } System.out.print(root.val + " "); for (TreeNode child : root.children) { preOrder(child); } } ``` 统计树中节点总数可以使用递归方式,每个节点的子节点数目即为它的贡献,加上1就是以它为根的子树的总节点数: ```java public int countNodes(TreeNode root) { if (root == null) { return 0; } int count = 1; for (TreeNode child : root.children) { count += countNodes(child); } return count; } ``` 最后可以通过一个示例来测试: ```java public static void main(String[] args) { TreeNode root = new TreeNode(1); TreeNode node2 = new TreeNode(2); TreeNode node3 = new TreeNode(3); TreeNode node4 = new TreeNode(4); TreeNode node5 = new TreeNode(5); TreeNode node6 = new TreeNode(6); TreeNode node7 = new TreeNode(7); root.children.add(node2); root.children.add(node3); root.children.add(node4); node2.children.add(node5); node2.children.add(node6); node4.children.add(node7); System.out.print("Pre-order traversal: "); preOrder(root); System.out.println(); System.out.println("Total number of nodes: " + countNodes(root)); } ``` 输出结果: ``` Pre-order traversal: 1 2 5 6 3 4 7 Total number of nodes: 7 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值