开发者社区> 问答> 正文

HDFS 的 API 操作中文件如何下载?

HDFS 的 API 操作中文件如何下载?

展开
收起
芯在这 2021-12-11 12:06:35 379 0
1 条回答
写回答
取消 提交回答
  • @Test public void testCopyToLocalFile() throws IOException, InterruptedException, URISyntaxException{

    // 1 获取文件系统

    Configuration configuration = new Configuration();

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

    // 2 执行下载操作

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

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

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

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

    fs.copyToLocalFile(false, new Path("/banzhang.txt"), new Path("e:/banhua.txt"), true);

    // 3 关闭资源 fs.close(); }

    HDFS文件夹删除

    @Test public void testDelete() throws IOException, InterruptedException, URISyntaxException{

    // 1 获取文件系统

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

    // 2 执行删除 fs.delete(new Path("/0508/"), true);

    // 3 关闭资源 fs.close(); }

    2021-12-11 12:20:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Boot2.0实战Redis分布式缓存 立即下载
CUDA MATH API 立即下载
API PLAYBOOK 立即下载