线程"main"中的异常java.lang.IllegalArgumentException:错误的FS:预期:file:/// [英] Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: expected: file:///
本文介绍了线程"main"中的异常java.lang.IllegalArgumentException:错误的FS:预期:file:///的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用java实现 copyFromLocal
命令,以下是我的代码.
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);
}
}
我收到以下异常:
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)
我将这些罐子添加到类路径中: hadoop-0.20.1-core.jar
commons-logging-1.1.3.jar
I added these jars to classpath:
hadoop-0.20.1-core.jar
commons-logging-1.1.3.jar
请提示我要去哪里.
推荐答案
按如下所示更改配置
conf.set("fs.default.name","hdfs://sandbox.hortonworks.com:8020");
请在您的目标destPath中提供相对路径,例如
Please Give a relative path in your destination destPath like
Path destPath = new Path("/user/Deepthy");
这将解决问题
这篇关于线程"main"中的异常java.lang.IllegalArgumentException:错误的FS:预期:file:///的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文