package week01;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Before;
import org.junit.Test;
public class HdfsUtil {
FileSystem fs = null;
@Before
public void init() throws IOException, InterruptedException, URISyntaxException{
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://week01:9000");
//fs = FileSystem.get(conf);
fs = FileSystem.get(new URI("hdfs://week01:9000"), conf, "hadoop");
}
/**
* 使用封装好的方法 上传文件
* @throws IllegalArgumentException
* @throws IOException
*/
@Test
public void upload2() throws IllegalArgumentException, IOException{
fs.copyFromLocalFile(new Path("c:/test.txt"), new Path("hdfs://week01:9000/aa/test2.txt"));
}
}
使用封装好的方法上传文件
最新推荐文章于 2021-05-07 22:14:40 发布