使用JAVA将文件从HDFS复制到本地文件系统

时间:2012-02-29 06:05:44

标签: hadoop mapreduce hdfs

我正在尝试将文件从HDFS复制到本地文件系统进行预处理。以下代码应根据文档工作。虽然它没有给出任何错误消息并且mapreduce作业运行顺利但我在本地硬盘上看不到任何输出。您认为问题是什么?谢谢。

        try {
            Path phdfs_input = new Path("hdfs://master:54310/user/hduser/conninput/"+value.toString());
            Path plocal_input = new Path("/home/hduser/Desktop/"+avlue.toString());
            FileSystem fs = FileSystem.get(context.getConfiguration());
            fs.copyToLocalFile(phdfs_input, plocal_input);

           /* String localoutput_file = "/home/hduser/Destop/output/"+value.toString();
            String cmd1[] = {"mafia", "-mfi", ".5", "-ascii", "~/Desktop/"+value.toString(), localoutput_file };
            File mafia_dir = new File("/home/hduser/");
            ShellCommandExecutor s = new ShellCommandExecutor(cmd1, mafia_dir);*/
        } catch (Exception e) {
            e.printStackTrace();
        }

1 个答案:

答案 0 :(得分:2)

尝试在/user/hduser/conninput/"+value.toString()构造函数中使用Path,而不是提供master:54310部分。它应该从master:54310中找出Configuration