每日总结

 

HDFSAPI案例实操

3.2.1 HDFS文件上传(测试参数优先级

1编写源代码

@Test

public void testCopyFromLocalFile() throws IOException, InterruptedException, URISyntaxException {

 

    // 1 获取文件系统

    Configuration configuration = new Configuration();

    configuration.set("dfs.replication", "2");

    FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:8020"), configuration, "atguigu");

 

    // 2 上传文件

    fs.copyFromLocalFile(new Path("d:/sunwukong.txt"), new Path("/xiyou/huaguoshan"));

 

    // 3 关闭资源

    fs.close();

2)将hdfs-site.xml拷贝到项目的resources资源目录下

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

 

<configuration>

<property>

<name>dfs.replication</name>

         <value>1</value>

</property>

</configuration>

3)参数优先级

参数优先级排序1客户端代码中设置的值 >2ClassPath下的用户自定义配置文件 >3然后是服务器的自定义配置(xxx-site.xml) >(4)服务器的默认配置(xxx-default.xml)

posted @ 2021-11-20 13:46  小萌新一枚lll  阅读(48)  评论(0编辑  收藏  举报