1

I ran into a problem running the program on a cluster and decided to read from hdfs file in functions map and reduce. How to read line by line hdfs file and burn to read rows in ArrayList?

1
  • Using TextInputFormat the default InputSplit is a FileInputSplit and will represent a full line. What exactly is the problem you're having? Commented Oct 31, 2012 at 22:21

1 Answer 1

1

Just a code snippet for demonstration:

Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(context.getConfiguration()); // context of mapper or reducer
FSDataInputStream fdsis = fs.open(path);
BufferedReader br = new BufferedReader(new InputStreamReader(fdsis));
String line = "";
ArrayList<String> lines = new ArrayList<String>();
while ((line = br.readLine()) != null) {
    lines.add(line);
}
br.close();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.