Hadoop目录/文件上次修改时间 [英] Hadoop dir/file last modification times
本文介绍了Hadoop目录/文件上次修改时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法获得hdfs中所有dirs和文件的最后修改时间?我想创建一个显示信息的页面,但我不知道如何在一个.txt文件中获取最后一个mod时间。
解决方案看看它是否有帮助:
public class HdfsDemo {
public static void main(String [] args)抛出IOException {
Configuration conf = new Configuration();
conf.addResource(new Path(/ Users / miqbal1 / hadoop-eco / hadoop-1.1.2 / conf / core-site.xml));
conf.addResource(new Path(/ Users / miqbal1 / hadoop-eco / hadoop-1.1.2 / conf / hdfs-site.xml));
FileSystem fs = FileSystem.get(conf);
System.out.println(输入目录名称:);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Path path = new Path(br.readLine());
displayDirectoryContents(fs,path);
fs.close();
}
private static void displayDirectoryContents(FileSystem fs,Path rootDir){
// TODO自动生成的方法存根
try {
FileStatus [] status = fs.listStatus(rootDir); (FileStatus file:status){
if(file.isDir()){
System.out.println(DIRECTORY:+ file.getPath()+ - 上次修改time:+ file.getModificationTime());
displayDirectoryContents(fs,file.getPath());
} else {
System.out.println(FILE:+ file.getPath()+ - 最后修改时间:+ file.getModificationTime());
catch(IOException e){
e.printStackTrace();
$ / code $ / pre
有一点需要注意, getModificationTime()从1970年1月1日起以毫秒形式返回文件的修改时间。
Is there a way to get the last modified times of all dirs and files in hdfs? I want to create page that displays the information, but I have no clue how to go about getting the last mod times all in one .txt file.
解决方案 See if it helps :
public class HdfsDemo {
public static void main(String[] args) throws IOException {
Configuration conf = new Configuration();
conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/core-site.xml"));
conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/hdfs-site.xml"));
FileSystem fs = FileSystem.get(conf);
System.out.println("Enter the directory name : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Path path = new Path(br.readLine());
displayDirectoryContents(fs, path);
fs.close();
}
private static void displayDirectoryContents(FileSystem fs, Path rootDir) {
// TODO Auto-generated method stub
try {
FileStatus[] status = fs.listStatus(rootDir);
for (FileStatus file : status) {
if (file.isDir()) {
System.out.println("DIRECTORY : " + file.getPath() + " - Last modification time : " + file.getModificationTime());
displayDirectoryContents(fs, file.getPath());
} else {
System.out.println("FILE : " + file.getPath() + " - Last modification time : " + file.getModificationTime());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
One thing to notice though, getModificationTime() returns the modification time of file in milliseconds since January 1, 1970 UTC.
这篇关于Hadoop目录/文件上次修改时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文