您需要列出源目录中的文件并使用迭代器复制每个文件
Path source=new Path("hdfs://HANameService/sources/hpm_support/apc_code/");
Path target=new Path("hdfs://HANameService/staging/hpm_support/apc_code/");
FileSystem fs = source.getFileSystem(conf);
RemoteIterator sourceFiles = fs.listFiles(source, true);
if(sourceFiles != null) {
while(sourceFiles.hasNext()){
FileUtil.copy(fs, sourceFiles.next().getPath(), fs, target, true, conf);
}
}
希望它对你有所帮助