Mapreduce程序无法读取输入文件

时间:2015-07-02 16:05:42

标签: java hadoop mapreduce hdfs

我在此位置的Start -> Control Panel -> System -> Advanced. Click on Environment Variables, under System Variables, find PATH, and click on it. Add python directory to path ,end it with ; 上有一个小csv个文件:hdfs。我在"hdfs://csehadoop/user/department.csv"程序中使用以下代码来读取文件的内容并将其存储在mapreduce中。

hashmap

但是,结果brReader = new BufferedReader(new FileReader("hdfs://csehadoop/user/department.csv")); while ((strLineRead = brReader.readLine()) != null) { String deptFieldArray[] = strLineRead.split(","); System.out.println(deptFieldArray[2].toString()); String businessId = deptFieldArray[2].toString(); String fields = deptFieldArray[3].toString() + "\t" + deptFieldArray[10].toString(); DepartmentMap.put(businessId, fields); } hashmap)始终为DepartmentMap。我怎么能纠正这个?

1 个答案:

答案 0 :(得分:0)

您无法以这种方式阅读Hdfs文件。您必须在指定的路径处打开FSDataInputStream。例如:

Path pt = new Path("hdfs://csehadoop/user/department.csv");
FileSystem fs = FileSystem.get(context.getConfiguration());
BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));