Hadoop之HDFS的API操作文件的上传下载参数的优先级
package com.itnihao.hdfs; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.net.URI; public class TestHDFS { private FileSystem fs; private URI uri; private Configuration conf; private String user; @Before public void init() throws IOException, InterruptedException { uri = URI.create("hdfs://hadoop102:8020"); conf = new Configuration(); // 设置副本数 //conf.set("dfs.replication","2"); user = "itnihao"; fs = FileSystem.get(uri,conf,user); } @After public void close() throws IOException { fs.close(); } @Test public void testHDFS() throws IOException, InterruptedException { // 创建文件系统对象 URI uri = URI.create("hdfs://hadoop102:8020"); Configuration conf = new Configuration(); String user = "itnihao"; FileSystem fs = FileSystem.get(uri,conf,user); System.out.println("fs = " + fs); fs.mkdirs(new Path("/testhdfs")); fs.close(); } @Test public void testUpLoad() throws IOException { fs.copyFromLocalFile(false,true,new Path("D:/bigdata/haohaoxuexi.txt"),new Path("/testhdfs")); } @Test public void testDownLoad() throws IOException { fs.copyToLocalFile(false, new Path("/testhdfs/haohaoxuexi.txt"), new Path("D:\\bigdata\\haohaoxuexi.txt"), false); } }Hadoop之HDFS的API操作文件的上传下载参数的优先级
标签:HDFS,fs,Path,上传下载,Hadoop,IOException,conf,new,import From: https://www.cnblogs.com/haizinihao/p/17374633.html