我首先使用Hadoop汇编Cloudera。我需要用HDFS在Linux服务器中制作目录。
但是当我在cmd Linux中使用java时,它不是创建目录,而是创建文件。
你能帮我做什么不好吗,你能解释一下,在我的代码 java 附近在 hdfs 和文件中创建目录。谢谢。对不起,英语不好。
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/
为我工作