“Wrong FS… expected: file:///” when trying to copyFromLocalFile from HDFS in Java

泄露秘密 提交于 2019-12-11 05:22:36

问题


I am trying to copy abc.json from port/example_File/2017 to another location /port/example_File/2018 in HDFS, by below code

String exampleFile= "hdfs://port/example_File/2017/abc.json"
String targetFile="hdfs://port/example_File/2018"
hdfs.copyFromLocalFile(new Path(exampleFile),new Path(targetFile))

I am getting below exception

    org.jboss.resteasy.spi.UnhandledException: 
java.lang.IllegalArgumentException: Wrong FS:
 hdfs://port/example_File/2017/abc.json, expected: file:///

How to copy file from one location to another in HDFS

Thanks,


回答1:


copyFromLocal is to copy files from Local Filesystem to HDFS.

To copy files within an HDFS cluster, use FileUtil.copy() and specify same Filesystem for both srcFS and dstFs.

Use DistCp when copying large number of files within a HDFS cluster or between two different HDFS clusters. Refer DistCp Java API here.



来源:https://stackoverflow.com/questions/43155247/wrong-fs-expected-file-when-trying-to-copyfromlocalfile-from-hdfs-in-jav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!