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.执行主文件
[[email protected] hadoop]# hadoop jar /usr/local/software/JarCreateDir.jar
3.查看HDFS中是否存在创建的test1文件
[[email protected] hadoop]# hadoop dfs -ls /user/root/
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/8933.html