繁体   English   中英

如何在HDFS Hadoop(Cloudera)Java中制作目录文件

[英]How make directory to file in HDFS Hadoop (Cloudera) java

我首先使用Hadoop程序集Cloudera。 我需要使用HDFS在Linux服务器中建立文件目录。 但是,当我在cmd Linux中使用Java时,它不会创建目录,而是创建文件。 您能帮我做我做的不好的事吗,我可以在我的代码java附近在hdfs和file中创建目录。谢谢。 对不起,英语不好)

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class FileDemo {

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

    Scanner reader = new Scanner(System.in);
    boolean success = false;

    System.out.println("Enter path of directory to create");
    String dir = reader.nextLine();

    // Creating new directory in Java, if it doesn't exists
    File directory = new File(dir);
    if (directory.exists()) {
        System.out.println("Directory already exists ...");

    } else {
        System.out.println("Directory not exists, creating now");

        success = directory.mkdir();
        if (success) {
            System.out.printf("Successfully created new directory : %s%n", dir);
        } else {
            System.out.printf("Failed to create new directory: %s%n", dir);
        }
    }

    // Creating new file in Java, only if not exists
    System.out.println("Enter file name to be created ");
    String filename = reader.nextLine();

    File f = new File(filename);
    if (f.exists()) {
        System.out.println("File already exists");

    } else {
        System.out.println("No such file exists, creating now");
        success = f.createNewFile();
        if (success) {
            System.out.printf("Successfully created new file: %s%n", f);
        } else {
            System.out.printf("Failed to create new file: %s%n", f);
        }
    }

    // close Scanner to prevent resource leak
    reader.close();

}

}

当我想在HDFS上建立目录时,可以从命令行进行。 在命令提示符下尝试

hadoop fs -mkdir /input

那应该在HDFS中创建一个名为input的文件夹。

这个网站上 ,我找到了

URI uri=URI.create (“hdfs://host: port/path”);

我相信应该为您创建目录。

hadoop fs -mkdir -p /home/hduser/wordcount/input/ 

为我工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM