开发者社区 问答 正文

HDFS的API操作文件上传的方法是什么?

HDFS的API操作文件上传的方法是什么?

展开
收起
游客y244y7ln2rlpa 2021-12-07 06:43:14 596 分享 版权
1 条回答
写回答
取消 提交回答
  • 文件上传的方法:``` //文件上传 @Test public void testCopyFromLocalFile() throws IOException,InterruptedException,URISyntaxException{

        //1 获取fs对象 hdfs://主节点名称:9000,"master"为所属用户
        Configuration conf = new Configuration();      
        FileSystem fs;
        fs = FileSystem.get(new URI("hdfs://master:9000"),conf,"master");
    
        //2 执行上传文件API 第一个路径为本地文件所在路径,第二个为要上传到的路径
        fs.copyFromLocalFile(new Path("D:\\idea project\\hdfs\\banzhang.txt"),new Path("/0316/dashen/banzhang/banzhang.txt"));
    
        //3 关闭资源
        fs.close();
        System.out.println("OVER AGAIN");
    }
    
    2021-12-07 06:43:54
    赞同 展开评论
问答分类:
API
问答地址: