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

上一篇:json信息的后台到前台的传输


下一篇:java模拟登陆功能