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