gpt4 book ai didi

java - 线程 "main"java.lang.IllegalArgumentException : Wrong FS: expected: file:///中的异常

转载 作者:可可西里 更新时间:2023-11-01 15:12:27 26 4
gpt4 key购买 nike

我正在尝试使用 java 实现 copyFromLocal 命令,下面是我的代码。

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)

我将这些 jar 添加到类路径中:
hadoop-0.20.1-core.jar
commons-logging-1.1.3.jar

请指出我哪里出错了。

最佳答案

修改配置如下

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

请在目标路径中给出一个相对路径,例如

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

这将解决问题

关于java - 线程 "main"java.lang.IllegalArgumentException : Wrong FS: expected: file:///中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34334338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com