gpt4 book ai didi

java - Hadoop JAr 中的 newFolderPath=Path.mergePaths(workingDir, newFolderPath)

转载 作者:可可西里 更新时间:2023-11-01 16:02:50 26 4
gpt4 key购买 nike

我将使用 hadoop jar 写入 hdfs。这是我的代码:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class WriteInrix {
public static void main(String[] args) throws Exception {
FileSystem hdfs = FileSystem.get(new Configuration());
Path homeDir = hdfs.getHomeDirectory();
System.out.println("Home folder -" + homeDir);
Path workingDir = hdfs.getWorkingDirectory();
System.out.println(workingDir);

Path newFolderPath = new Path("/MyDataFolder");
newFolderPath = Path.mergePaths(workingDir, newFolderPath);

if (hdfs.exists(newFolderPath)) {
hdfs.delete(newFolderPath, true);
}

hdfs.mkdirs(newFolderPath);

Path localFilePath = new Path("test.csv");
Path hdfsFilePath = new Path(newFolderPath + "test1.csv");
hdfs.copyFromLocalFile(localFilePath, hdfsFilePath);
}
}

此处的问题出在行 newFolderPath = Path.mergePaths(workingDir, newFolderPath); 中。此行给出了一个错误,因为 Path 没有为 mergePaths() 定义任何内容。但是我从可靠的来源复制了代码。有什么问题?我应该使用什么替代方案?

最佳答案

我想看看你得到的确切错误。从你的代码来看,唯一让我印象深刻的是你应该这样做:

Path homeDir = new Path(hdfs.getHomeDirectory());

Path workingDir = new Path(hdfs.getWorkingDirectory());

我刚刚开始学习 Java/Hadoop,所以我可能是错的。如果这有效,请告诉我。

关于java - Hadoop JAr 中的 newFolderPath=Path.mergePaths(workingDir, newFolderPath),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37865459/

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