Reading data through the FileSystem API

Source: Internet
Author: User

Referring to the previous reading of data through a Hadoop URL, it is sometimes impossible to set up an URLStreamHandlerFactory instance in an application, in which case the FileSystem API is required to open the input stream of a file

Using filesystem to display files in the Hadoop file system in a standard output format

The procedure is as follows:

 PackageCom.lcy.hadoop.file;ImportJava.io.InputStream;ImportJava.net.URI;Importorg.apache.hadoop.conf.Configuration;ImportOrg.apache.hadoop.fs.FileSystem;ImportOrg.apache.hadoop.fs.Path;Importorg.apache.hadoop.io.IOUtils; Public classFilesystemcat { Public Static voidMain (string[] args)throwsexception{//TODO auto-generated Method StubString uri=args[0]; Configuration conf=NewConfiguration (); FileSystem FS=Filesystem.get (Uri.create (URI), conf); InputStream in=NULL; Try{ in=fs.open (NewPath (URI)); Ioutils.copybytes (in, System.out,4096,false); }finally{ioutils.closestream (in); }    }}

To run the example:

Reading data through the FileSystem API

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.