Java program to read a file from Hadoop Cluster 2

Hadoop

You need to look at the following blog posts to understand this post in a better way.

  1. Copying the File to HDFS file system
  2. A java program to read the file from HDFS

We already wrote a program to read the file from HDFS. Why the hell we do it again? Tom says, URL.setURLStreamHandlerFactory() method we used in the previous program can be called only once in a JVM. That’s why we execute it inside the static block. In a collaborative development environment, it will be difficult to track this. (Is it a limitation of URL.setURLStreamHandlerFactory()???)

So we use the FileSystem API to do the same operation – read the file and display it on the console!

import java.io.*;
import java.net.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.*;
public class FileSystemCat{
    public static void main(String [] args) throws Exception{
        String uri=args[0];
        Configuration conf= new Configuration();
  …

View original post 120 more words

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s