The Hdfs-javaapi of Hadoop

Source: Internet
Author: User

Environment configuration

You first need to configure the Hadoop_classpath variable in hadoop-env.sh:

Export Hadoop_classpath=/home/hadoop/hadoop-1.2.1/myclass

Configure Java_home in. Bash_profile and take effect

Test program

Urlcat.javaimport org.apache.hadoop.fs.fsurlstreamhandlerfactory;import org.apache.hadoop.io.ioutils ;import java.io.inputstream;import java.net.url;public class urlcat {   Static {    url.seturlstreamhandlerfactory (New fsurlstreamhandlerfactory ());   }  public static void main (String[] args)  throws Exception  {    InputStream in = null;    try {       in = new url (Args[0]). OpenStream ();       ioutils.copybytes (In, system.out, 4096, false);    }     finally {      ioutils.closestream (in);     }  }}JAVAC -CLASSPATH&NBSP, .... /hadoop-core-1.2.1.jar urlcat.java hadoop urlcat hdfs://hadoop1:9000/usEr/hadoop/inp/test2.txt 

By introducing Classpath and import, you can use this urlcat to read files through the HDFs API.

API Online Brochure: http://hadoop.apache.org/docs/r1.2.1/api/index.html

Using Ant

It is also a compile software for Apache, and it is also used for compiling. Complete the project compilation.

: http://ant.apache.org/bindownload.cgi

wget http://mirror.bit.edu.cn/apache//ant/binaries/apache-ant-1.9.4-bin.tar.gz# Download Reference code: Wget-so 11101.zip http://www.packtpub.com/code_download/11101unzip 11101.zipcd 7287os_code/7287os_code/chapter2ls-  L Total 8drwxrwxr-x 2 Hadoop hadoop 4096 Apr 2 18:07 hdfs_c_apidrwxrwxr-x 3 Hadoop hadoop 4096 Apr 2 18:07 HDFS_JAVA_APICD hdfs_java_api/

Export hadoop_home=/home/hadoop/hadoop-1.2.1 #建议放到. Bash_profile/home/hadoop/apache-ant-1.9.4/bin/ant #进行编译.. #在当前目录下会生成一个HDFSJavaAPI. jar# in the build directory is the class file # Execute API Jar package for testing. Hadoop jar Hdfsjavaapi.jar Hdfsjavaapidemo


This article is from the "Xiaofeng Moon" blog, make sure to keep this source http://kinda22.blog.51cto.com/2969503/1582559

The Hdfs-javaapi of Hadoop

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.