10月3日总结

HDFS文件下载

@Test

public void testCopyToLocalFile() throws IOException, InterruptedException, URISyntaxException{

 

    // 1 获取文件系统

    Configuration configuration = new Configuration();

    FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:8020"), configuration, "atguigu");

   

    // 2 执行下载操作

    // boolean delSrc 指是否将原文件删除

    // Path src 指要下载的文件路径

    // Path dst 指将文件下载到的路径

    // boolean useRawLocalFileSystem 是否开启文件校验

    fs.copyToLocalFile(false, new Path("/xiyou/huaguoshan/sunwukong.txt"), new Path("d:/sunwukong2.txt"), true);

   

    // 3 关闭资源

    fs.close();

}

注意:如果执行上面代码,下载不了文件,有可能是你电脑的微软支持的运行库少,需要安装一下微软运行库。

posted @ 2023-10-03 19:12  lcz111  阅读(12)  评论(0)    收藏  举报