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]