1. Create the HDFs directory and make a jar package
1 PackageHdfs;2 3 Importjava.io.IOException;4 ImportJava.net.URI;5 6 Importorg.apache.hadoop.conf.Configuration;7 ImportOrg.apache.hadoop.fs.FileSystem;8 ImportOrg.apache.hadoop.fs.Path;9 /**Ten * Create an HDFs directory One * @authorSimonszhao A * - */ - Public classCreatedir { the Public Static voidMain (string[] args) { -String uri = "Hdfs://neusoft-master:9000/user/root/test1"; -Configuration conf =NewConfiguration (); - Try { +FileSystem fs =Filesystem.get (Uri.create (URI), conf); -Path DFS =NewPath ("Hdfs://neusoft-master:9000/user/root/test1"); + Fs.mkdirs (DFS); A}Catch(IOException e) { at e.printstacktrace (); - } - } -}
Java code create HDFS directory
2. Executing the Master file
[Email protected] hadoop]# Hadoop Jar/usr/local/software/jarcreatedir.jar
3. See if there is a test1 file created in HDFs
[Email protected] hadoop]# Hadoop dfs-ls/user/root/
Java Code Operation HDFS (Create a catalog below/user/root/)