Changes between Initial Version and Version 1 of waue/2010/0115-get


Ignore:
Timestamp:
Jan 19, 2010, 7:22:51 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2010/0115-get

    v1 v1  
     1
     2
     3{{{
     4#!java
     5import java.io.IOException;
     6
     7import org.apache.hadoop.conf.Configuration;
     8import org.apache.hadoop.fs.FileSystem;
     9import org.apache.hadoop.fs.Path;
     10
     11
     12public class GetFromHdfs {
     13        // 將檔案從hdfs下載回local, src 為 hdfs的來源, dst 為 local 的目的端
     14        static boolean getFromHdfs(String src,String dst, Configuration conf) {
     15                Path dstPath = new Path(src);
     16                try {
     17                        // 產生操作hdfs的物件
     18                        FileSystem hdfs = dstPath.getFileSystem(conf);
     19                        // 下載
     20                        hdfs.copyToLocalFile(false, new Path(src),new Path(dst));
     21                       
     22                } catch (IOException e) {
     23                        e.printStackTrace();
     24                        return false;
     25                }
     26                return true;
     27        }
     28        static public void main(String args[]){
     29                Configuration conf = new Configuration();
     30                String src = "/user/waue/input";
     31                String dst = "/home/waue/input";
     32                boolean status = getFromHdfs(src, dst, conf);
     33                System.err.println("create? :" + status);
     34               
     35        }
     36}
     37
     38
     39}}}