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 }
2.执行主文件
[root@neusoft-master hadoop]# hadoop jar /usr/local/software/JarCreateDir.jar
3.查看HDFS中是否存在创建的test1文件
[root@neusoft-master hadoop]# hadoop dfs -ls /user/root/