まずHadoopアセンブリClouderaを使用します。 私はHDFSでLinuxサーバにファイルを保存するディレクトリを作成する必要があります。 しかし、私はcmd LinuxでJavaを使用すると耐性を作成しませんが、ファイルを作成します。 あなたは私が悪いことを手伝ってもらえますか?私のコードjavaの近くで、hdfsとfileの中に耐性を作り出すことができます。ありがとう。 )悪い英語のため申し訳ありませんディレクトリをHDFSでファイル化する方法Hadoop(Cloudera)java
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に関連するのかわかりません。 – Serhiy
HDFSにディレクトリを作成しますか?どのようにすればいいのか教えてください – VasyPupkin
プログラム的にやりたいのであれば、https://hadoop.apache.org/docs/r2.6.1/api/org/apache/hadoop/fs/FileSystem.htmlクラスをチェックしてください。 – Serhiy