1、window hadoop 安装

 

 

 2、hadoop 配置

 

 

 

 

 

 

 

 

 注dfs.permissions.enabled =false 权限放开

 

 

 

 

 

 

 

 

 

 

 

 3、hadoop 启动

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4、Idea+hadoop

  1)、pom.xml

<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.13.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.5.2</version>
        </dependency>

 

 

 

 2)、增删改查询实例

 

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URI;

public class HadoopClients {
    static FileSystem fileSystem = null;

    public static void main(String[] args) throws Exception {
        //mkdir();

        //mv();

        /* rm();*/

        up();

        /*see();*/

        //readWrite();
    }

    //静态代码块

    static {
        Configuration conf = new Configuration();
        //hadoop的链接对象
        try {
            fileSystem = FileSystem.get(new URI(“hdfs://127.0.0.1:9000″),conf,”root”);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //创建目录
    public static void mkdir() throws Exception{
        fileSystem.mkdirs(new Path(“/test3”));
        System.out.println(“创建成功!!”);
    }

    //修改目录
    public static void mv() throws Exception{
        fileSystem.rename(new Path(“/test1”),new Path(“/test2”));
        System.out.println(“修改成功!!”);
    }

    //删除目录
    public static void rm() throws Exception{
        fileSystem.delete(new Path(“/test2”),true);
        System.out.println(“删除成功!!”);
    }

    //上传数据
    public static void up() throws Exception{
        fileSystem.copyFromLocalFile(new Path(“c:\\aa.txt”),new Path(“/test2”));
        System.out.println(“上传成功!!”);
    }

    //查看目录
    public static void see() throws Exception{
        RemoteIterator<LocatedFileStatus> iterator = fileSystem.listFiles(new Path(“/”), true);
        //迭代器取数据
        while (iterator.hasNext()){
            LocatedFileStatus next = iterator.next();
            System.out.println(next.getPath());
            System.out.println(next.getLen());
            System.out.println(next.getBlockSize());
            System.out.println(next.getReplication());
            System.out.println(“————————————-“);
        }
    }

    

}

 

 

 

 

 

 

 

 

 

https://www.cnblogs.com/geeksongs/p/14204767.html

版权声明:本文为Happy_EveryDay原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/smallfa/p/16374545.html