使用 Java 将文件移动到 HDFS

Ped*_*ves 3 java hadoop text-files hdfs

如何使用Java执行hadoop put文件到hdfs中?这可能吗?

使用这个语句:

public abstract boolean rename(Path src, Path dst) throws IOException
Run Code Online (Sandbox Code Playgroud)

谢谢!

Dan*_*n W 5

您应该能够使用copyFromLocalFile

Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path localPath = new Path("path/to/local/file");
Path hdfsPath = new Path("/path/in/hdfs");
fs.copyFromLocalFile(localPath, hdfsPath);
Run Code Online (Sandbox Code Playgroud)