◢ <[wiki:III140412/Lab9 實作九]> | <[wiki:III140412 回課程大綱]> ▲ | <[wiki:III140412/Lab11 實作十一]> ◣ = 實作十 Lab10 = {{{ #!html

Hadoop FileSystem API 實作(一)
Local 檔案上傳到 HDFS
Upload Local Files and Directories to HDFS

}}} [[PageOutline]] {{{ #!text 請先連線至 nodeN.3du.me , N 為您的報名編號 }}} * 在上一個實作中,我們可以觀察 !FsShell.java 是如何使用 Path、Configration、!FileSystem 這幾個類別。 * 我們從模仿 hadoop fs -put 對應的函數 copyFromLocal(Path[] srcs, String dstf) 可以重新撰寫一個 Java Application 來學習 Hadoop !FileSystem API {{{ #!java 121 /** 122 * Add local files to the indicated FileSystem name. src is kept. 123 */ 124 void copyFromLocal(Path[] srcs, String dstf) throws IOException { 125 Path dstPath = new Path(dstf); 126 FileSystem dstFs = dstPath.getFileSystem(getConf()); 127 if (srcs.length == 1 && srcs[0].toString().equals("-")) 128 copyFromStdin(dstPath, dstFs); 129 else 130 dstFs.copyFromLocalFile(false, false, srcs, dstPath); 131 } }}} * 讓我們先來觀察程式運作的情形,請剪貼以下步驟,並嘗試思考觀察到的現象(特別是 hadoop fs -ls 列出的結果差異): {{{ cd ~/hadoop_labs/lab004 ant hadoop fs -ls hadoop fs -rmr input hadoop jar copyFromLocal.jar doc input hadoop fs -ls touch test hadoop jar copyFromLocal.jar test file hadoop fs -ls export HADOOP_CONF_DIR=~/hadoop/conf.local/ hadoop fs -ls hadoop jar copyFromLocal.jar doc input hadoop fs -ls hadoop jar copyFromLocal.jar test file hadoop fs -ls unset HADOOP_CONF_DIR ant clean }}}