HDFS-how to read file content from HDFS

Source: Internet
Author: User
Tags hadoop fs

Use this command bin/Hadoop fs-cat to read the file content on HDFS to the console.

You can also use HDFS APIs to read data. As follows:

Import java.net. URI;
Import java. io. InputStream;
Import org. apache. hadoop. conf. Configuration;
Import org. apache. hadoop. fs. FileSystem;
Import org. apache. hadoop. fs. Path;
Import org. apache. hadoop. io. IOUtils;
Public class FileCat
{
Public static void main (String [] args) throws Exception
{
If (args. length! = 1 ){
System. out. println ("Usage FileCat <target> ");
System. exit (1 );
}
Configuration conf = new Configuration ();
FileSystem hdfs = FileSystem. get (URI. create (args [0]), conf );
InputStream in = null;
Try {
In = hdfs. open (new Path (args [0]);
IOUtils. copyBytes (in, System. out, 4096, true );
} Finally {
IOUtils. closeStream (in );
}
}
}

Copy local files to HDFS

Download files from HDFS to local

Upload local files to HDFS

Common commands for HDFS basic files

Introduction to HDFS and MapReduce nodes in Hadoop

Hadoop practice Chinese version + English version + Source Code [PDF]

Hadoop: The Definitive Guide (PDF]

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.