003. Java connection Hadoop2.5.1 get file system Information

Source: Internet
Author: User
Tags dateformat

Description:Hadoop installation, a total of three deployment methods, respectively, are local deployment, pseudo-distributed deployment, cluster deployment. Here we take the pseudo-distribution pattern as an example to explain.

software:myeclipse-2014-ga, Hadoop-2.5.1.tar.gz,hadoop-eclipse-plugin-2.5.0.jar

Software: Link: http://pan.baidu.com/s/1ntuUhux Password: Stok

1, first copy the Hadoop-eclipse-plugin-2.5.0.jar to the MyEclipse plug-in directory inside

  

2. Start MyEclipse and see if the plug-in is installed successfully

  

  

3, configuration plug-in information,:

  

  

Note: Host is a cluster host ip,port:50020 is the default, the right port is the information configured in the cluster core-site.xml

4, after the configuration is complete, create a new project, here I built a Java project

  

1  PackageHadoop;2 3 Importjava.io.IOException;4 ImportJava.text.DateFormat;5 Importjava.util.Date;6 7 Importorg.apache.hadoop.conf.Configuration;8 ImportOrg.apache.hadoop.fs.FileStatus;9 ImportOrg.apache.hadoop.fs.FileSystem;Ten ImportOrg.apache.hadoop.fs.Path; One  A  Public classHadooptest { -      Public Static voidMain (string[] args)throwsIOException { -System.out.println ("12"); theConfiguration conf =NewConfiguration (); -Conf.set ("Fs.defaultfs", "hdfs://192.168.0.204:9000"); -FileSystem fs =filesystem.get (conf); -Filestatus[] s = fs.liststatus (NewPath ("/")); +          for(inti = 0; i < s.length; i++) { -Filestatus f =S[i]; + System.out.println (F.getpath (). GetName ()); A System.out.println (F.getlen ()); at System.out.println (F.getmodificationtime ()); -Date Date =NewDate (F.getmodificationtime ()); -String d =dateformat.getdateinstance (). Format (date); - System.out.println (d); -         } - fs.close (); in     } -}
View Code

5. After successful operation, the file information obtained from the cluster will be displayed.

  

  

003, Java connection Hadoop2.5.1 get file system Information

Related Article

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.