【发布时间】:2018-05-09 10:16:11
【问题描述】:
我是大数据的新手,正在处理一项小任务,我需要将多个文件合并到 hdfs 中的单个文件中。我正在使用 Java 程序来完成此操作(将所有类似于 prod* 的文件合并到一个 prod.txt 文件中)。我已经寻求帮助,到目前为止我编写的代码是:
公共类 MergeFiles {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
String srcPath = "/user/demouser/first/prod*";
String dstPath = "/user/demouser/second/prod.txt";
Configuration conf = new Configuration();
conf.set("fs.default.name","http://hostname:portnumber/");
try
{
FileSystem hdfs = FileSystem.get(conf);
FileUtil.copyMerge(hdfs, new Path(srcPath), hdfs, new Path(dstPath), false, conf, null);
}
catch (IOException e)
{ }
}
}
它不工作,我无法弄清楚如何解决这个问题。我也不明白“fs.default.name”的工作原理。请帮忙。
【问题讨论】:
-
如何将您的 srcPath 更改为您的文件夹名称。我也很好地使用了这个 api 请显示你的日志
-
该属性已被弃用。应该是
fs.defaultFS,需要指向namenode -
除此之外,您正在重新发明轮子。搜索一个叫做 filecrush 的东西。或者至少,Pig 可以在大约 3 行代码中做到这一点