Lab11 – Reading from HDFS & charting

Hi Hadoopers,

This is another simple exercise to read a file from HDFS.

You already know from the previous post Lab 08 – MapReduce using custom class as Key that we have 3 outputs from the reducer.


Here is a program that reads these files using Java API and prepare a chart. Here is the flow diagram.


Here is the code.

package org.grassfield.hadoop.output;

import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

 * This will read the reducer output and export to desired format (HTML)
 * @author pandian
public class FeedCategoryHtml {

    public static void main(String[] args) throws IOException {
        Path path = new Path("hdfs://gandhari:9000"+args[0]);
        FileSystem fs = FileSystem.get(new Configuration());
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        StringBuffer opBuffer = new StringBuffer();
        String line=null;
            StringTokenizer st = new StringTokenizer(line, "\t");
            opBuffer.append("['"+st.nextToken()+"', "+st.nextToken()+"],\n");
        StringBuffer htmlBuffer = new StringBuffer();
        FileReader fr = new FileReader(args[1]);
        br = new BufferedReader(fr);
        String htmlOut = htmlBuffer.toString();
        htmlOut = htmlOut.replaceAll("MROUTPUT", opBuffer.toString());


I know you’d be excited to see the results. Here you go.


See you in another interesting post. Bye for now!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s