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


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

--

Legend:

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

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