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");
    }
}

 

上一篇:获得android应用的版本号


下一篇:使用java进行Hadoop文件上传下载和遍历