HelloWorld of the HDFS API

Source: Internet
Author: User

1. Source Code

Import org.apache.hadoop.fs.fsurlstreamhandlerfactory;import org.apache.hadoop.io.ioutils;import  java.io.inputstream;import java.net.url;/** * example 3.1 */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 {&nbsP;           ioutils.closestream (in);         }    }}
package cn.kissoft.hadoop.week04;import org.apache.hadoop.conf.configuration;import  Org.apache.hadoop.fs.filesystem;import org.apache.hadoop.fs.path;import org.apache.hadoop.io.ioutils ;import java.io.inputstream;import java.net.uri;/** * example 3.2 */public  Class homework1 {    public static void main (String[] args)  throws Exception {        String uri =  args[0];        configuration conf = new  Configuration ();         filesystem fs = filesystem.get ( Uri.create (URI),  conf);        inputstream in =  null;        try {             in = fs.open (New path (URI));             Ioutils.copybytes (In, system.out, 4096, false);         } finally {             Ioutils.closestream (in);         }    }}

2. How to run the. Class

Note: In this example, the Urlcat class is in the default package, and if there is a package, the class name should be preceded by a packet.

3. How the. Jar Runs

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.