我想在每次运行作业时通过在文件名末尾附加时间戳来将 MapReduce 程序的输出文件添加到同一目录。
目前我可以在文件输出文件的末尾附加时间戳,但我无法找到如何将文件添加到同一输出目录而不是每次都覆盖它。
最佳答案
您可以在临时文件夹中写入输出文件,并在作业结束后将它们移动到目标文件夹。将所有文件从一个文件夹移动到另一个文件夹的方法示例:
public static void moveFiles(Path from, Path to, Configuration conf) throws IOException {
FileSystem fs = from.getFileSystem(conf); // get file system
for (FileStatus status : fs.listStatus(from)) { // list all files in 'from' folder
Path file = status.getPath(); // get path to file in 'from' folder
Path dst = new Path(to, file.getName()); // create new file name
fs.rename(file, dst); // move file from 'from' folder to 'to' folder
}
}
关于hadoop - 将输出文件添加到 Mapreduce 中的现有输出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622738/