HDFs Java Client Operation code (Windows above the jar package, submitted to Linux run)

Source: Internet
Author: User

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)

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.