• Java代码操作HDFS(在/user/root/下面創建目錄)


    1.创建HDFS目录并打成jar包

     1 package Hdfs;
     2 
     3 import java.io.IOException;
     4 import java.net.URI;
     5 
     6 import org.apache.hadoop.conf.Configuration;
     7 import org.apache.hadoop.fs.FileSystem;
     8 import org.apache.hadoop.fs.Path;
     9 /**
    10  * 创建HDFS目录
    11  * @author SimonsZhao
    12  *
    13  */
    14 public class CreateDir {
    15     public static void main(String[] args) {
    16         String uri = "hdfs://neusoft-master:9000/user/root/test1";
    17         Configuration conf = new Configuration();
    18         try {
    19             FileSystem fs = FileSystem.get(URI.create(uri),conf);
    20             Path dfs = new Path("hdfs://neusoft-master:9000/user/root/test1");
    21             fs.mkdirs(dfs);
    22         } catch (IOException e) {
    23             e.printStackTrace();
    24         }
    25     }
    26 }
    JAVA代码创建HDFS目录

    2.执行主文件

    [root@neusoft-master hadoop]# hadoop jar /usr/local/software/JarCreateDir.jar

    3.查看HDFS中是否存在创建的test1文件

    [root@neusoft-master hadoop]# hadoop dfs -ls /user/root/

    博客地址:http://www.cnblogs.com/jackchen-Net/
  • 相关阅读:
    JS 对象定义
    JavaScript HTML DOM 元素(节点)
    DOM 事件
    DOM CSS
    DOM HTML
    DOM 简介
    JS 验证
    JS 错误
    JavaScript Break 和 Continue 语句
    JS While
  • 原文地址:https://www.cnblogs.com/jackchen-Net/p/6266768.html
Copyright © 2020-2023  润新知