简体   繁体   English

Mapreduce程序无法读取输入文件

[英]Mapreduce program unable to read input file

I have a small csv file on hdfs in this location: "hdfs://csehadoop/user/department.csv" . 我有一个小csv文件上hdfs在以下位置: "hdfs://csehadoop/user/department.csv" I use the following code in my mapreduce program to read the contents of the file and store it in a hashmap . 我在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);
}

However, the resultant hashmap ( DepartmentMap ) is always null . 但是,结果hashmapDepartmentMap )始终为null How can I rectify this? 我该如何纠正?

You cannot read Hdfs files that way. 您不能以这种方式读取Hdfs文件。 You must open a FSDataInputStream at the indicated Path. 您必须在指定的路径上打开FSDataInputStream For instance: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM