Deepthy
Deepthy

Reputation: 139

Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: expected: file:///

I am trying to implement copyFromLocal command using java, below is my code.

package com.hadoop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


public class CopyFromLocal {

public static void main(String[] args) throws IOException, URISyntaxException {

    Configuration conf =new Configuration();
    conf.addResource(new Path("/usr/hdp/2.3.0.0-2557/hadoop/conf/core-site.xml"));
    conf.addResource(new Path("/usr/hdp/2.3.0.0-2557/hadoop/conf/mapred-site.xml"));
    conf.addResource(new Path("/usr/hdp/2.3.0.0-2557/hadoop/conf/hdfs-site.xml"));
    FileSystem fs = FileSystem.get(conf);
    Path sourcePath = new Path("/root/sample.txt");
    Path destPath = new Path("hdfs://sandbox.hortonworks.com:8020/user/Deepthy");
    if(!(fs.exists(destPath)))
    {
        System.out.println("No Such destination exists :"+destPath);
        return;
    }
fs.copyFromLocalFile(sourcePath, destPath);

}

}

I get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://sandbox.hortonworks.com:8020/user/Deepthy, expected: file:///
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:305)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:47)
at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:357)
at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:245)
at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:643)
at com.amal.hadoop.CopyFromLocal.main(CopyFromLocal.java:27)

I added these jars to classpath:
hadoop-0.20.1-core.jar
commons-logging-1.1.3.jar

Kindly suggest where I'm going wrong.

Upvotes: 1

Views: 3070

Answers (1)

Thanga
Thanga

Reputation: 8161

Change the configuration as below

conf.set("fs.default.name","hdfs://sandbox.hortonworks.com:8020");

Please Give a relative path in your destination destPath like

Path destPath = new Path("/user/Deepthy");

This will fix the issue

Upvotes: 2

Related Questions