将目录从本地系统复制到 hdfs java 代码 [英] copying directory from local system to hdfs java code
本文介绍了将目录从本地系统复制到 hdfs java 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在尝试使用 Java 代码将目录从本地系统复制到 HDFS 时遇到问题.我能够移动单个文件,但无法找到移动包含子文件夹和文件的整个目录的方法.任何人都可以帮助我吗?提前致谢.
I'm having a problem trying to copy a directory from my local system to HDFS using java code. I'm able to move individual files but can't figure out a way to move an entire directory with sub-folders and files. Can anyone help me with that? Thanks in advance.
推荐答案
只需使用 FileSystem
的 copyFromLocalFile 方法.如果源路径是本地目录,它将被复制到 HDFS 目标:
Just use the FileSystem
's copyFromLocalFile method. If the source Path is a local directory it will be copied to the HDFS destination:
...
Configuration conf = new Configuration();
conf.addResource(new Path("/home/user/hadoop/conf/core-site.xml"));
conf.addResource(new Path("/home/user/hadoop/conf/hdfs-site.xml"));
FileSystem fs = FileSystem.get(conf);
fs.copyFromLocalFile(new Path("/home/user/directory/"),
new Path("/user/hadoop/dir"));
...
这篇关于将目录从本地系统复制到 hdfs java 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文