HDFS错误整改
编写“远程客户端操作hdfs创建文件夹”代码,验证环境是否配置成功!
1、错误点1:

改正方法:
第一步:点击 文件>项目文件>模块

第二步:会发现红色框里的显示的是15,这里我们需要改成8,如下图:


2、错误点2:

改正方法:
第一步:点击 文件>项目文件>设置,后按照图中步骤点击:

第二步:将目标字节码版本同样换成8,如下图:

第三步:这个问题解决了
3、错误点3:
这里出现了uri爆红了,因该是可能是导包的时候出错的?
如果你是第一次将以上代码写入环境,会出现很多包显示红色,说明包没有被安装,需要点击maven,点击刷新键,自动检测安装!

改正方法:
第一步:点击侧面的Maven,后点击旋转按钮,后再次运行可以解决(?)

4、错误点4:
虽然网页中已经显示出xiyou,代表成功了,但是......

出现了如下警告:
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
警告util.NativeCodeLoader:无法为您的平台加载本机Hadoop库…在适用的情况下使用内置的java类

改正方法:
此处引用网上查找的文章,因为我第一步的文件就没找到,可能之前的步骤不一样。
(44条消息) 解决 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform...警告_青玄叶鹤的博客-CSDN博客


实验目的:
编写“远程客户端操作hdfs创建文件夹”代码,验证环境是否配置成功!
实现步骤:
1.首先要确保集群群起成功


2.在浏览器打开hadoop151:9870

3.编写如下图示代码
直接复制:- package org.example.hdfs;
- import org.apache.hadoop.conf.Configuration;
- 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;
- import java.net.URISyntaxException;
- import org.apache.hadoop.fs.FileSystem;
- public class HdfsClient {
- private FileSystem fs;
- @Before
- public void init() throws URISyntaxException, IOException, InterruptedException {
- // 连接的集群nn地址
- URI uri = new URI("hdfs://hadoop151:8020");
- // 创建一个配置文件
- Configuration configuration = new Configuration();
- // 用户
- String user = "root";
- // 1 获取到了客户端对象
- fs = FileSystem.get(uri, configuration, user);
- }
- @After
- public void close() throws IOException {
- // 3 关闭资源
- fs.close();
- }
- @Test
- public void testmkdir() throws URISyntaxException, IOException, InterruptedException {
- // 2 创建一个文件夹
- fs.mkdirs(new Path("/xiyou/huaguoshan1"));
- }
- }
复制代码 4.运行代码,在网页端察看远程客户端操作hdfs创建文件夹成功

如果友友们有疑问和指导,欢迎在评论区指出!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |