客户端代码的通用步骤:
1.创建客户端对象
2.使用客户端对象进行操作
3.关闭客户端对象
public class HDFS_Client {
private FileSystem fs;
private Configuration conf;
@Before //在test之前执行一次
public void init() throws URISyntaxException, IOException, InterruptedException {
//1. 创建客户端对象
conf = new Configuration();
//conf.set("fs.defaultFS","hdfs://hadoop102:8021");
conf.set("dfs.replication","2"); //设置副本数量为2
URI uri = new URI("hdfs://hadoop102:8020");
fs = FileSystem.get(uri, conf,"atguigu");
}
@After //在test之后执行一次
public void close() throws IOException {
fs.close();
}
@Test
public void mkdir() throws IOException {
fs.mkdirs(new Path("/JAVA"));
}
@Test
public void put() throws IOException {
/*
*参数解读
* 1.boolean delSrc,上传后是否删除源文件 windows
* 2.