Java API操作 上傳文件

Java API操作 上傳文件

package com.hdfs;


import java.net.URI;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Before;



public class HdfsTest2 {
    
    //獲取 FileSystem 對象
    private FileSystem fs=null;
    @SuppressWarnings("unused")
    private List<String> hdfsPathsLists;
    
    
    @Before
    public void init() throws Exception {
        Configuration con = new Configuration();
        con.setBoolean("dfs.support.append",true);
        fs = FileSystem.get(new URI("hdfs://192.168.119.128:9000"),
                con,"root");
        
    }
    
    public void testUploadFile() throws Exception{
        String src = "/home/cai/simple/HelloWorld.txt";
        String hdfsDst="/javaApi/mk/dir1";
        fs.copyFromLocalFile(new Path(src),new Path(hdfsDst));
        System.out.println("upload success");
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章