zoukankan      html  css  js  c++  java
  • 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目录里

    简单编码测试下

    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,若是运行成功则代表连接成功!
        }
    
    
    }
    
  • 相关阅读:
    临时文件服务器,配置共享文件夹
    封装扩展方法
    List.Insert
    VS 生成事件中xcopy失败
    创建型设计模式总结
    js提交图片转换为base64
    C#建造者模式
    echarts 立体柱
    k8s生产环境启用防火墙,要开启的端口
    一篇文章为你图解Kubernetes网络通信原理
  • 原文地址:https://www.cnblogs.com/shouyaya/p/14130657.html
Copyright © 2011-2022 走看看