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的FileSystem API进行文件操作,包括删除、复制和重命名文件的具体实现过程。通过示例代码展示了如何批量处理特定命名模式的文件,并提供了从一个目录移动文件到另一个目录的方法。

656

被折叠的 条评论
为什么被折叠?



