使用java程序合并hdfs中的文件

时间:2018-05-09 10:16:12

标签: java hadoop hdfs bigdata

我是大数据新手,正在开展一项小任务,我需要将多个文件合并到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"的工作原理。请帮忙。

1 个答案:

答案 0 :(得分:0)

您需要一个真实的主机名和端口号来替换' http://hostname:portnumber/',您的主机名和端口号必须可以从您的计算机访问。它应该是您的文件系统的位置。