0

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){
            }
        }
    }
1
  • Does the user you are trying to execute Java code owns the output file in HDFS? Commented May 21, 2015 at 7:04

2 Answers 2

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

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.