[英]Hadoop: How to move HDFS files in one directory to another directory?
我在HDFS中有一個HDFS源目錄和一個目標存檔目錄。 在每次運行作業的開始,我需要將Source目錄中存在的所有零件文件移動(或復制,然后刪除)到我的Archive目錄中。
SparkSession spark = SparkSession.builder().getOrCreate();
JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
String hdfsSrcDir = "hdfs://clusterName/my/source";
String archiveDir = "hdfs://clusterName/my/archive";
try{
FileSystem fs = FileSystem.get(new URI(hdfsSrcDir ),jsc.hadoopConfiguration());
}
我不知道該如何進一步。 目前,我的fs
對象僅引用我的源目錄。
我相信,創建具有存檔位置的fs2
不會有所幫助。
我發現了有關FileSystem.rename()
,但這需要使用文件名作為參數。 我需要將/my/source/*
移至/my/archive/
。
檢查這是否適合您,
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", "hdfs://xyz:1234");
FileSystem filesystem = FileSystem.get(configuration);
FileUtil.copy(filesystem, new Path("src/path"),
filesystem, new Path("dst/path"), false, configuration);
filesystem.delete(new Path("src/path"), true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.