java - Problems to emulate a "hdfs dfs -ls -R /" command in java
问题描述
I'm trying to programmatically get all the files under a given path using java code
public static List<String> listFilesFromHDFSPath(Configuration hadoopConfiguration, String hdfsPath)
throws IOException, IllegalArgumentException {
List<String> filePaths = new ArrayList<String>();
Path path = new Path(hdfsPath);
FileSystem fs = path.getFileSystem(hadoopConfiguration);
if(fs.isDirectory(path)){
FileStatus[] fileStatuses = fs.listStatus(path);
for(FileStatus fileStatus : fileStatuses){
if(fileStatus.isFile())
filePaths.add(fileStatus.getPath().toString());
}
}
else {
filePaths.add(path.toString());
}
fs.close();
return filePaths;
}
But this approach is now working for me, the process die after the line:
FileSystem fs = path.getFileSystem(hadoopConfiguration);
So I was trying to get a "hdfs dfs -ls -R" equivalent command in java like the one in Scala:
import scala.sys.process._
val lsResult = Seq("hdfs","dfs","-ls","-R","hdfs://path/demo/").!!
Is there something similar for java?
解决方案
推荐阅读
- acumatica - 需要隐藏按钮
- ruby-on-rails - 记录的 Rails 验证
- regex - 用于匹配 ts 文件但不测试的正则表达式
- python - Python 3 中的文件
- jq - jq 不适用于其中包含来自变量的破折号的键
- django - 请求更改/添加另一个应用程序中的数据
- java - 抛出 BeanCreationException 后如何关闭应用程序
- android-studio - Android Gradle Build 无故耗时过长
- python - 如何解决以下错误?scan0:获取接口标志时出错:没有这样的设备
- ios - 打开相机Swift时WKWebView关闭