java - Hadoop:Path.getFileSystem 与 FileSystem.get
问题描述
我正在编写一个 Java 类来创建 HDFS 目录,但想在创建目录之前检查该目录是否存在。我不确定是使用 Path.getFileSystem() 还是 FileSystem.get():
Configuration conf = new Configuration();
Path path = new Path(args[1]);
FileSystem fs = path.getFileSystem(conf);
if(fs.exists(path)) {
System.err.println("Dir already exists");
}
boolean status = fs.mkdirs(path);
或者我应该使用 FileSystem.get() 方法:
Configuration conf = new Configuration();
Path path = new Path(args[1]);
FileSystem fs = FileSystem.get(conf);
boolean status = fs.mkdirs(path);
if(!status) {
System.err.println("Dir already exists");
}
什么时候适合使用以下任何一种:Path.getFileSystem() 或 FileSystem.get()?
解决方案
这取决于您是否已经有一个非空Path
对象。
空安全方法是使用Configuration
具有静态方法的对象FileSystem.get(conf)
推荐阅读
- javascript - 使用 360° 视频创建一个球体,使用 A-Frame 实现了threejs
- c - STM32F4 的 USB CDC 设置和库问题
- android - 如何从云功能更新 Firestore 文档中的时间戳字段?
- angular - Angular 7如何使用自定义指令属性获取所有子元素
- python-3.x - 带有错误的非线性模型:将对象评估为数值
- javascript - 不可变地更新对象列表中的对象列表
- algorithm - 切换数组中的位对以最大化其与另一个数组的点积
- java - 如何勾选“按pdf页面大小选择纸张来源”iText7?
- android - 如何为 iOS 强制颤动设备方向
- git - git有某种缓存机制吗?