dilshad
dilshad

Reputation: 754

try to hadoop read from hdfs output

This is my program i want to read from my hdfs out which i create using map reduce program but it does not display any output. there is not any compile time and run time error.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

    public class Cat{
        public static void main (String [] args) throws Exception{
            try{
                Path pt=new Path("hdfs:/path/to/file");
                FileSystem fs = FileSystem.get(new Configuration());
                BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
                String line;
                line=br.readLine();
                while (line != null){
                    System.out.println(line);
                    line=br.readLine();
                }
            }catch(Exception e){
            }
        }
    }

Upvotes: 0

Views: 323

Answers (2)

Manoj Kumar G
Manoj Kumar G

Reputation: 502

Few things to note:

1) Are you using the correct hdfs path?

The path should be given like the one below if you are using cloudera on local machine.

Path pt=new Path("hdfs://localhost.localdomain:8020/user/cloudera/myfile.txt");

Check the "fs.defaultFS" property in core-site.xml to get the filesystem path (i.e hdfs://something.something:port/)

2) How you are executing the code? Try to create a jar and run it from the CLI using the below command

$ hadoop jar /home/cloudera/your/path/to/jar/myjar.jar  com.test.Myjar 

Try the above things and let us know if that works.

HTH

Upvotes: 0

Jérémy
Jérémy

Reputation: 108

I can't comment so I'll post an answer.

Handling that exception might help. What are you catching exactly ?

Upvotes: 1

Related Questions