当前位置: 首页 > news >正文

疫情最新数据消息成都搜索引擎优化包括哪些方面

疫情最新数据消息成都,搜索引擎优化包括哪些方面,做网站域名的公司,厦门教育平台网站建设文章目录 API文档环境配置API操作准备工作创建文件夹文件上传文件下载文件删除文件的更名和移动获取文件详细信息 API文档 HDFS API官方文档:https://hadoop.apache.org/docs/r3.3.1/api/index.html 环境配置 将Hadoop的Jar包解压到非中文路径(例如D:…

文章目录

    • API文档
    • 环境配置
    • API操作
      • 准备工作
      • 创建文件夹
      • 文件上传
      • 文件下载
      • 文件删除
      • 文件的更名和移动
      • 获取文件详细信息

API文档

HDFS API官方文档:https://hadoop.apache.org/docs/r3.3.1/api/index.html

环境配置

将Hadoop的Jar包解压到非中文路径(例如D:\hadoop\hadoop-2.7.2)

配置HADOOP_HOME环境变量

在这里插入图片描述

配置Path环境变量

在这里插入图片描述

API操作

准备工作

创建一个[Maven]工程HdfsClientDemo

引入hadoop-client依赖

<dependencies><dependency><grupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.7.2</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.30</version></dependency></dependencies>

创建HdfsClient 类

创建文件夹

public class HdfsClient {//创建目录@Testpublic void testMkdir() throws URISyntaxException, IOException, InterruptedException {//连接的集群nn地址URI uri = new URI("hdfs://node1:8020");//创建一个配置文件Configuration configuration = new Configuration();//用户String user = "atguigu";//1、获取到了客户端对象FileSystem fileSystem = FileSystem.get(uri, configuration, user);//2、创建一个文件夹fileSystem.mkdirs(new Path("/xiyou/huaguoshan"));//3、关闭资源fileSystem.close();}
}

上面这样写代码有点冗余,我们通过AOP切面将初始化和关流的操作拆分出来,后续只需要关注核心逻辑就可以了。
实际开发中这样设计也不太好,建议搞个工厂类

public class HdfsClient {private FileSystem fs;@Beforepublic void init() throws URISyntaxException, IOException, InterruptedException {// 连接的集群nn地址URI uri = new URI("hdfs://node1:8020");// 创建一个配置文件Configuration configuration = new Configuration();configuration.set("dfs.replication", "2");// 用户String user = "atguigu";// 1、获取到了客户端对象fs = FileSystem.get(uri, configuration, user);}@Testpublic void testMkdir() throws URISyntaxException, IOException, InterruptedException {//创建一个文件夹fs.mkdirs(new Path("/xiyou/huaguoshan2"));}@Afterpublic void close() throws IOException {// 3、关闭资源fs.close();}}

文件上传

@Testpublic void testPut() throws IOException {// 参数解读,参数1:表示删除原数据、参数2:是否允许覆盖、参数3:原数据路径、参数4:目的地路径fs.copyFromLocalFile(false, true, new Path("D:\\bigData\\file\\sunwukong.txt"), new Path("hdfs://node1/xiyou/huaguoshan"));}

文件下载

    //文件下载@Testpublic void testGet() throws IOException {//参数的解读,参数一:原文件是否删除、参数二:原文件路径HDFS、参数三:Windows目标地址路径、参数四:crc校验
//        fs.copyToLocalFile(false, new Path("hdfs://node1/xiyou/huaguoshan2/sunwukong.txt"), new Path("D:\\bigData\\file\\download"), false);fs.copyToLocalFile(false, new Path("hdfs://node1/xiyou/huaguoshan2/"), new Path("D:\\bigData\\file\\download"), false);
//      fs.copyToLocalFile(false, new Path("hdfs://node1/a.txt"), new Path("D:\\"), false);}

文件删除

//删除
@Test
public void testRm() throws IOException {//参数解读,参数1:要删除的路径、参数2:是否递归删除//删除文件//fs.delete(new Path("/jdk-8u212-linux-x64.tar.gz"),false);//删除空目录//fs.delete(new Path("/xiyou"), false);//删除非空目录fs.delete(new Path("/jinguo"), true);
}

文件的更名和移动

//文件的更名和移动
@Test
public void testmv() throws IOException {//参数解读,参数1:原文件路径、参数2:目标文件路径//对文件名称的修改fs.rename(new Path("/input/word.txt"), new Path("/input/ss.txt"));//文件的移动和更名fs.rename(new Path("/input/ss.txt"), new Path("/cls.txt"));//目录更名fs.rename(new Path("/input"), new Path("/output"));
}

获取文件详细信息

    //获取文件详细信息@Testpublic void fileDetail() throws IOException {//获取所有文件信息RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);//遍历文件while (listFiles.hasNext()) {LocatedFileStatus fileStatus = listFiles.next();System.out.println(fileStatus.getPath());System.out.println(fileStatus.getPermission());System.out.println(fileStatus.getOwner());System.out.println(fileStatus.getGroup());System.out.println(fileStatus.getLen());System.out.println(fileStatus.getModificationTime());System.out.println(fileStatus.getReplication());System.out.println(fileStatus.getBlockSize());System.out.println(fileStatus.getPath().getName());//获取块信息BlockLocation[] blockLocations = fileStatus.getBlockLocations();System.out.println(Arrays.toString(blockLocations));}}
http://www.hkea.cn/news/244818/

相关文章:

  • 武汉网站设计制作外包公司的人好跳槽吗
  • 网站建设哪里最好页面关键词优化
  • 清远建设网站制作seo系统培训课程
  • 网站的网页建设知识ppt北大青鸟职业技术学院简介
  • 巫山网站设计aso优化榜单
  • 关于节约化建设网站的表态发言网站制作报价表
  • 建行网站是多少呢故事式的软文广告例子
  • 阳江市住房和城乡规划建设局网站一级消防工程师考试
  • 做课件的网站有哪些用html制作淘宝网页
  • 网站开发前后台整个流程品牌宣传的推广
  • 深圳市门户网站建设网站推广优化方法
  • 中山公司注册网页怎么优化
  • 网站建设怎么分录2022年新闻摘抄简短
  • 江西景德镇建设厅网站太原关键词排名推广
  • 番禺做网站自媒体发布平台有哪些
  • 用dede做的网站首页电子商务网络营销
  • 最好的做任务赚钱网站网络域名怎么查
  • 建设部规范网站百度app关键词优化
  • 骏域网站百度怎么收录网站
  • 网站robots.txt查看九江seo公司
  • 建设阿里妈妈网站搜索引擎排名优化seo
  • 自学网站建设作业创建网站免费
  • 营销网站定制的优势成品网站源码的优化技巧
  • 高职学院网站建设方案广告制作
  • table表格 做的网站营销案例分析报告模板
  • pc端网站做移动适配教育培训机构管理系统
  • 页游传奇排行榜无锡seo优化公司
  • 广西南宁网站设计百度seo算法
  • 网站建设服务怎么样近期国内热点新闻事件
  • 阿里巴巴网站国际站建设seo托管服务