码迷,mamicode.com
首页 > Windows程序 > 详细

hdfs的相关api

时间:2020-12-18 13:06:56      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:files   图片   dfs   mic   end   except   目录   roo   source   

连接hdfs

根据hdfs的版本引用相关的hdfs依赖

        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.6.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.6.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.6.5</version>
        </dependency>

将hdfs中的core-site.xmlhdfs-site.xml放进项目的resources目录里

技术图片

简单编码测试下

public class Connection {
    public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
        Configuration configuration=new Configuration();
        System.setProperty("HADOOP_USER_NAME", "root");
        FileSystem fs = FileSystem.get(configuration);
        System.out.println(fs.getHomeDirectory());
        //拿到FileSystem后可以简单操作下hdfs,若是运行成功则代表连接成功!
    }


}

hdfs的相关api

标签:files   图片   dfs   mic   end   except   目录   roo   source   

原文地址:https://www.cnblogs.com/shouyaya/p/14130657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!