gpt4 book ai didi

java - Hadoop HDFS PutMerge 不起作用

转载 作者:可可西里 更新时间:2023-11-01 15:37:16 25 4
gpt4 key购买 nike

我尝试在我的计算机上运行 PutMerge in Hadoop in Action。但它不起作用。我在本地机器上创建了几个文件以下是代码

package org.apache.hadoop.examples;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class PutMerge {

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

Configuration conf = new Configuration();
FileSystem hdfs = FileSystem.get(conf);
FileSystem local = FileSystem.getLocal(conf);

Path inputDir = new Path("/home/yehang/Documents/example");
Path hdfsFile = new Path("hdfs://localhost:54310:/user/yehang");

//System.out.println(inputDir);
//System.out.println(hdfsFile);

try {
FileStatus[] inputFiles = local.listStatus(inputDir);
//System.out.println(inputFiles);
FSDataOutputStream out = hdfs.create(hdfsFile);
//System.out.println(out);

for (int i = 0; i < inputFiles.length; i++) {
System.out.println(inputFiles[i].getPath().getName());
FSDataInputStream in = local.open(inputFiles[i].getPath());
byte buffer[] = new byte[256];
int bytesRead = 0;
while ((bytesRead = in.read(buffer)) > 0) {
out.write(buffer, 0, bytesRead);
}
in.close();
}
out.close();
} catch (IOException e) {
e.printStackTrace();

}

}

当我在 hadoop 上运行它时,出现以下错误:

  Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS:        hdfs://localhost:54310:/user, expected: file:///
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:381)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:55)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:335)
at org.apache.hadoop.fs.ChecksumFileSystem.mkdirs(ChecksumFileSystem.java:492)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:377)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:364)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:555)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:536)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:443)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:435)
at org.apache.hadoop.examples.PutMerge.main(PutMerge.java:28)

谁能帮帮我?

最佳答案

Hadoop分布式文件系统(HDFS)相关类文件定义在项目hadoop-hdfs中。因此,您必须在 Java 类路径中导入 jar hadoop-hdfs-*.jar 才能解决此问题。

关于java - Hadoop HDFS PutMerge 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23098675/

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