1. Display the contents of the Demo1 file on the screen via Java.net.URL
1 PackageHdfs;2 ImportJava.io.InputStream;3 ImportJava.net.URL;4 Importorg.apache.hadoop.fs.FsUrlStreamHandlerFactory;5 Importorg.apache.hadoop.io.IOUtils;6 7 Public classJardemo {8 Static{9Url.seturlstreamhandlerfactory (Newfsurlstreamhandlerfactory ());Ten } One Public Static voidMain (string[] args) { AInputStream in =NULL; - Try { -in=NewURL (args[0]). OpenStream (); theIoutils.copybytes (in, System.out, 4096,false); -}Catch(Exception e) { - e.printstacktrace (); -}finally{ + Ioutils.closestream (in); - } + A } at}
Display the contents of a file in HDFs
2. Package The above Java file into a jar package
(1) Right mouse button export
(2) Find the Jar file entry
(iii) Enter the path where the jar package is stored
(4) The main class where the jar package is located is selected in the selection box below, if this part does not do, it needs to display the main class when running the jar package in Linux. such as Com.hdfs
3. Package is stored at the specified location and transferred to the corresponding/usr/local/txtnode on Linux via CRT
such as running this jar package.
The problem: Because the input parameter is a directory and not a file error.
To resolve this issue: (1) Prepare a demo1 file to be uploaded to HDFs
(2) Upload to HDFs command
(3) Execute again to display the contents of Demo1
HDFs Java Client Operation code (Windows above the jar package, submitted to Linux run)