Java Code Operation HDFS (Create a catalog below/user/root/)

Source: Internet
Author: User

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/)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.