hadoop filesystem 删除文件 复制文件 重命名文件

hadoop filesystem 删除文件 复制文件 重命名文件

private void moveFile(Configuration conf, String Path1, String Path2, String newname ) throws IOException {
FileSystem fs = FileSystem.get(conf);
FileStatus[] status = fs.globStatus(new Path(Path1+"cookie*"));
Path[] paths = FileUtil.stat2Paths(status);
for (Path i : paths) {
fs.delete(i, true);
}

Path dir = new Path(Path1); // Path1 对应的目录不存在时,需要创建

if(!fs.exists(dir))  fs.mkdirs(dir);

status = fs.globStatus(new Path(Path2+"part*"));
paths = FileUtil.stat2Paths(status);
for (Path i : paths) {
FileUtil.copy(fs, i, fs, dir, false, conf);
}

Path f = new Path(newname);
if (fs.exists(f))
fs.delete(f, true);
fs.rename(new Path(Path1), new Path(newname));
}

你可能感兴趣的:(Hadoop,hadoop,filesystem)