【发布时间】:2020-07-24 17:20:17
【问题描述】:
我正在尝试查找触发器文件是否存在于 hdfs 目录中。
代码:
private static final int index = 23;
@SuppressWarnings("serial")
private static HashMap<String, Boolean> files = new HashMap<String, Boolean>() {{
put("/user/ct_troy/allfiles/_TRIG1", false);
put("/user/ct_troy/allfiles/_TRIG2", false);
put("/user/ct_troy/allfiles/_TRIG3", false);
put("/user/ct_troy/allfiles/_TRIG4", false);
put("/user/ct_troy/allfiles/_TRIG5", false);
}};
private static boolean availableFiles(String file_name){
Configuration config = new Configuration();
config.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
config.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
try {
FileSystem hdfs = FileSystem.get(config);
// Hadoop DFS Path - Input file
Path path = new Path(file_name); // file_name - complete path and file name.
// Check if input is valid
if (hdfs.exists(path) == false) {
System.out.println(file_name + " not found.");
throw new FileNotFoundException(file_name.substring(index));
}
else{
System.out.println(file_name + " File Present.");
return true;
}
}catch (IOException e) {
}
return false;
}
我将HashMap<> files 的键作为file_name 参数传递给函数availableFiles。
我构建了一个 jar 并在节点上运行它,它给了我以下输出:
_TRIG2 not found.
_TRIG3 not found.
_TRIG1 not found.
_TRIG4 not found.
_TRIG5 not found.
不确定为什么会发生这种情况,_TRIG1、_TRIG2 和 _TRIG3 存在,而 _TRIG4 和 _TRIG5 不存在。对于所有触发器文件,它给了我相同的结果。帮助。
【问题讨论】:
-
你好,也许你可以关注一下:stackoverflow.com/a/25645225/390462