Java实现获取HDFS子目录数量_Java实现读取HDFS目录
LOG.info("檢查是否有當(dāng)前日期的目錄");
fsUtil.checkDirExists(new File(configUtil.readConfig("download.file.path") + currentDay));
FSDataInputStream in = null;
LOG.info("生成以JobID命名的目錄");
String fileName = configUtil.readConfig("download.file.path") + currentDay + "/" + jobID + ".csv";
File file = new File(fileName);
List> dataList = new ArrayList<>();
InputStreamReader inputStreamReader = null;
try {
String dataPath = configUtil.readConfig("offLine.data.path") + currentDay + "/" + jobID + ".csv/";
LOG.info(dataPath);
Path path = new Path(dataPath);
Configuration configuration = dfsUtil.getHadoopConf();
FileSystem hdfs = FileSystem.get(configuration);
BufferedReader br = null;
if (hdfs.exists(path) && hdfs.isDirectory(path)) {
FileStatus[] srcFileStatus = hdfs.listStatus(path);
for (FileStatus fs : srcFileStatus) {
if (fs.getLen() > 0) {
String line;
in = hdfs.open(fs.getPath());
inputStreamReader = new InputStreamReader(in, "UTF-8");
br = new BufferedReader(inputStreamReader);
while ((line = br.readLine()) != null) {
dataList.add(Lists.newArrayList(new String(line.getBytes(Constant.CODE_FORMAT))));
}
}
}
}
} catch (Exception error) {
error.getMessage();
error.printStackTrace();
} finally {
org.apache.hadoop.io.IOUtils.closeStream(in);
}
總結(jié)
以上是生活随笔為你收集整理的Java实现获取HDFS子目录数量_Java实现读取HDFS目录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 短语_从Java中的文本文件中
- 下一篇: JAVA CGI 远程代码执行_Apac