1

hdfsのすべてのディレクトリとファイルの最終変更時刻を取得する方法はありますか? 情報を表示するページを作成したいのですが、最終変更時刻をすべて 1 つの .txt ファイルで取得する方法がわかりません。

4

3 に答える 3

1

おそらく、各パスのステータスを取得するには、ファイルとディレクトリを反復処理する必要があります-以下のコード(単なるサンプル)を使用できます-しかし、ファイルのセットが大きい場合、それがどれほど効率的かはわかりませんおよびディレクトリ。

Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://<namenod_ip_address:<port>");
conf.set("mapred.job.tracker", "<jobtracker_ip_address>:<port>");
conf.setBoolean("fs.hdfs.impl.disable.cache", true);

FileSystem lfs = FileSystem.get(l_configuration);
fs.getFileStatus(new Path("/your/path")).getModificationTime();
于 2013-08-04T19:07:09.113 に答える
1

それが役立つかどうかを確認してください:

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();
        }
    }
}

ただし、getModificationTime()は、1970 年 1 月 1 日 UTC からのミリ秒単位でファイルの変更時間を返します。

于 2013-08-05T06:51:39.303 に答える