怎样在hdfs上创建多级目录文件夹_【Hadoop】如何在hdfs根目录下创建文件夹

shell命令创建文件夹

启动hdfs,终端输入:start-dfs.sh

在hdfs中创建一个input文件夹:hadoop fs -mkdir /input/1

使用参数-p创建多级目录:hadoop fs -mkdir -p /input/file1

HDFS Java API创建public class CreatDir {

public static void main(String[] args) throws IOException{

Configuration conf=new Configuration();

conf.set("fs.defaultFS","hdfs://centos01:9000");

//conf.set("fs.defaultFs","hdfs://主节点名(或者主节点的地址):9000"),此处centos01是主节点名

//或者conf.set("fs.default.name","hdfs://centos01:9000");

FileSystem hdfs = FileSystem.get(conf);

boolean isok = hdfs.mkdirs(new Path("hdfs:/input"));

if(isok) {

System.out.println("sucess!");

}else {

System.out.println("fall");

}

hdfs.close();

}}

你可能感兴趣的:(怎样在hdfs上创建多级目录文件夹_【Hadoop】如何在hdfs根目录下创建文件夹)