@Test
public void copyToLocalFile() throws Exception{
//创建配置文件对象
Configuration configuration = new Configuration();
//生成文件系统对象
FileSystem fileSystem = FileSystem.get(new URI("hdfs://node1:9820"), configuration, "root");
/**3.调用下载API方法
* delSrc – whether to delete the src 是否原文件,false不删除,true表示删除原文件
* src – path:被下载文件的全路径名对应的Path类的对象
* dst – path:文件下载到的目标全路径名对应的Path类的对象
* useRawLocalFileSystem – 是否开启文件校验.
*/
fileSystem.copyToLocalFile(false,new Path("/api/hhnew.txt"),new Path("D:/HH.txt"),true);
fileSystem.close();
}

HDFS之JavaAPI下载文件_文件系统