[0011] windows 下 eclipse 開發 hdfs程式範例 (三)

來源:互聯網
上載者:User

標籤:strong   start   開發   搭建   puts   tle   學習   load   pat   

目的:

學習windows 開發hadoop程式的配置。

 

[0007] windows 下 eclipse 開發 hdfs程式範例 

太麻煩

[0010] windows 下 eclipse 開發 hdfs程式範例 (二)

輸出日誌變化,而且配置似乎很麻煩。

 

環境:

windows 7 64下 eclipse

 

說明:

該實踐是在[0008] Windows 7 下 hadoop 2.6.4 eclipse 本地開發調試配置 中設定後進行的,

在這裡面進行了一些環境變數設定、外掛程式安裝。 

如果按照以下步驟進行,還有報錯的話,可以參考這篇文章,以及問題[0009] 解決

 

1.建立項目

建立項目、匯入hadoop開發包

詳細參考

[0007] windows 下 eclipse 開發 hdfs程式範例  1 建立項目

 

2.建立類,編寫如下代碼  
 1 package hdfs; 2  3 import java.io.FileNotFoundException; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6  7 import org.apache.commons.compress.utils.IOUtils; 8 import org.apache.hadoop.conf.Configuration; 9 import org.apache.hadoop.fs.FSDataInputStream;10 import org.apache.hadoop.fs.FileSystem;11 import org.apache.hadoop.fs.Path;12 13 /**14  *  功能:      將 hdfs://ssmaster:9000/data/paper.txt下載到Windows下c:\paper.txt15  *  調用方式:hadoop jar 打包包名.jar  16  */17 18 public class Down_Load {19 20     public static void main(String[] args) {21         22     Configuration conf =new Configuration();23     conf.set("fs.defaultFS", "hdfs://ssmaster:9000/");24     25     FileSystem fs = null;26     Path src = null;27     FSDataInputStream in = null;28     FileOutputStream out = null;29       30     src = new Path("hdfs://ssmaster:9000/data/paper.txt" );31     32     try {33         34       fs = FileSystem.get(conf) ;35       in = fs.open(src);36 37        } catch (IOException e) {38         e.printStackTrace(); 39     }40     41     try {42         out = new FileOutputStream ("c:\\paper.txt"); //等效  c:/paper.txt43     } catch (FileNotFoundException e) {44         e.printStackTrace();45     }46     47     try {48         IOUtils.copy(in, out);49     } catch (IOException e) {50         e.printStackTrace();51     }52 53 }54 }
View Code

備忘: 在[0007] 第2步的代碼上 增加 conf.set("fs.defaultFS", "hdfs://ssmaster:9000/");

 

3 執行

右鍵->run java application

 

總結:

HDFS下的windows開發環境基本搭建好。

 

[0011] windows 下 eclipse 開發 hdfs程式範例 (三)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.