hdfs的相关api

连接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目录里

hdfs的相关api

简单编码测试下

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

上一篇:如何使用PS磨皮美白 PS快速美白磨皮的5种方法介绍


下一篇:Win7系统运行PyCharm报错:无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll