[0011] Windows Eclipse Development HDFS Program sample (III)

Source: Internet
Author: User

Objective:

Learn the configuration of Windows development Hadoop programs.

[0007] Example of an Eclipse development HDFs program under Windows

Too much trouble

[0010] Windows Eclipse Development HDFS Program sample (II)

Output log changes, and configuration seems to be cumbersome.

Environment:

Windows 7 64 under Eclipse

Description

This practice was made after the [0008] Windows 7 Hadoop 2.6.4 Eclipse Local Development Debug configuration was set up,

There are some environment variable settings, plug-ins installed in this area.

If you follow the steps below and have an error, you can refer to this article as well as the question [0009] to resolve

1. New Project

Create a new project, import a Hadoop development package

Detailed reference

[0007] Windows Eclipse Development HDFs Program Example 1 new project

2. Create a new class and write the following code
1  PackageHDFs;2 3 Importjava.io.FileNotFoundException;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 7 Importorg.apache.commons.compress.utils.IOUtils;8 Importorg.apache.hadoop.conf.Configuration;9 ImportOrg.apache.hadoop.fs.FSDataInputStream;Ten ImportOrg.apache.hadoop.fs.FileSystem; One ImportOrg.apache.hadoop.fs.Path; A  - /** - * Function: Download hdfs://ssmaster:9000/data/paper.txt to Windows C:\paper.txt the * Calling Method: Hadoop jar package name. Jar -  */ -  -  Public classDown_load { +  -      Public Static voidMain (string[] args) { +          AConfiguration conf =NewConfiguration (); atConf.set ("Fs.defaultfs", "Hdfs://ssmaster:9000/"); -      -FileSystem fs =NULL; -Path src =NULL; -Fsdatainputstream in =NULL; -FileOutputStream out =NULL; in        -src =NewPath ("Hdfs://ssmaster:9000/data/paper.txt" ); to      +     Try { -          theFS =filesystem.get (conf); *in =Fs.open (SRC); $ Panax Notoginseng}Catch(IOException e) { - e.printstacktrace (); the     } +      A     Try { theout =NewFileOutputStream ("C:\\paper.txt");//equivalent C:/paper.txt +}Catch(FileNotFoundException e) { - e.printstacktrace (); $     } $      -     Try { - ioutils.copy (in, out); the}Catch(IOException e) { - e.printstacktrace ();Wuyi     } the  - } Wu}
View Code

Remark: Add Conf.set ("Fs.defaultfs", "hdfs://ssmaster:9000/") to the code of Step 2nd of [0007];

3 execution

Right-click->run Java application

Summary:

The Windows Development environment under HDFS is basically well-built.

[0011] Windows Eclipse Development HDFS Program sample (III)

Related Article

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.