Question

Maybe my question is a bit stupid, but I want to access hdfs file on host Windows environment, specifically, in eclipse. Hadoop and all related stuff is installed on VirtualBox (used Hortonworks Sandbox env. With Centos OS). On virtual machine I can work with hdfs without issues, tried to access hdfs://192.168.56.101:8020/user/root/vectors/dictionary.file-0. Tried on eclipse to access this, but got a exception.

So, is there any way to do it? If it is possible, a example would be great to get.

Was it helpful?

Solution

The main cause of the problem was that system did not know who I am. I was needed a client of hadoop, so the problem was solved by adding client dependency into pom:

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-client</artifactId>
        <version>2.2.0</version>
    </dependency>

And here is the working example:

public static void main(String[] args) throws Exception {
    try {
        Configuration conf = new Configuration();
        conf.set("fs.default.name", "hdfs://192.168.56.101:8020");
        FileSystem fs = FileSystem.get(conf);
        Path pt = new Path("/user/root/vectors/dictionary.file-0");
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
        try {
            String line;
            line = br.readLine();
            while (line != null) {
                System.out.println(line);
                line = br.readLine();
            }
        } finally {
            br.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top