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

wordpress成品网站yunbuluo网站编辑怎么做

wordpress成品网站yunbuluo,网站编辑怎么做,wordpress 导航模板,青岛网站排名公司HDFS的API操作 1 HDFS 核心类简介 Configuration类:处理HDFS配置的核心类。 FileSystem类:处理HDFS文件相关操作的核心类,包括对文件夹或文件的创建,删除,查看状态,复制,从本地挪动到HDFS文件系统中等。…

HDFS的API操作

1 HDFS 核心类简介

Configuration类:处理HDFS配置的核心类。

FileSystem类:处理HDFS文件相关操作的核心类,包括对文件夹或文件的创建,删除,查看状态,复制,从本地挪动到HDFS文件系统中等。

Path类:处理HDFS文件路径。

IOUtils类:处理HDFS文件读写的工具类。

2 HDFS文件处理类FileSystem的核心方法介绍:

1. FileSystem get(URI uri, Configuration conf)根据HDFSURI和配置,创建FileSystem实例2. public boolean mkdirs(Path f) throws IOException根据路径创建HDFS文件夹3. FSDataOutput Stream create(Path f, boolean overwrite)根据具体的路径创建文件,并且知名是否以重写的方式4. abstract boolean delete(Path f, boolean recursive)根据路径删除文件5. abstract FileStatus[] listStatus(Path f)根据路径,返回该路径下所有文件夹或文件的状态。6. Void moveFromLocalFile(Path src, Path dst)将本地路径下的文件,挪动到HDFS的指定路径下7. FSDataInputStream open(Path f)打开指定路径下的文件内容

3 执行流程

maven依赖

<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>RELEASE</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.8.2</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-common</artifactId><version>3.3.2</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>3.3.2</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-hdfs</artifactId><version>3.3.2</version></dependency></dependencies>

hdfs 创建文件夹

   public static void main(String[] args) throws IOException, Exception, URISyntaxException {Configuration conf = new Configuration();
//		conf.set("fs.defaultFS", "hdfs://hadoop102:9000");// 1 获取hdfs客户端对象
//		FileSystem fs = FileSystem.get(conf );FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf, "root");// 2 在hdfs上创建路径fs.mkdirs(new Path("/dir01/"));// 3 关闭资源fs.close();System.out.println("over");}

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

// 1 文件上传@Testpublic void testCopyFromLocalFile() throws IOException, InterruptedException, URISyntaxException{// 1 获取fs对象Configuration conf = new Configuration();conf.set("dfs.replication", "2");FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 执行上传APIfs.copyFromLocalFile(new Path("e:/info.txt"), new Path("/file1.txt"));// 3 关闭资源fs.close();}

2 HDFS文件下载

  // 2 文件下载@Testpublic void testCopyToLocalFile() throws URISyntaxException, IOException, InterruptedException {// 1 获取对象Configuration conf = new Configuration();// conf.set("dfs.replication", "2");FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 执行下载操作
//		fs.copyToLocalFile(new Path("/banhua.txt"), new Path("e:/banhua.txt"));fs.copyToLocalFile(false, new Path("/file1.txt"), new Path("e:/file2.txt"), true);// 3 关闭资源fs.close();}

3 HDFS文件夹删除

// 3 文件删除@Testpublic void testDelete() throws IOException, InterruptedException, URISyntaxException{// 1 获取对象Configuration conf = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 文件删除fs.delete(new Path("/dir01"), true);// 3 关闭资源fs.close();}

4 HDFS文件名更改

// 4 文件更名@Testpublic void testRename() throws IOException, InterruptedException, URISyntaxException{// 1 获取对象Configuration conf = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 执行更名操作fs.rename(new Path("/file1.txt"), new Path("/file111.txt"));// 3 关闭资源fs.close();}

5 HDFS文件详情查看

查看文件名称、权限、长度、块信息

// 5 文件详情查看@Testpublic void testListFiles() throws IOException, InterruptedException, URISyntaxException{// 1 获取对象Configuration conf = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 查看文件详情RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);while(listFiles.hasNext()){LocatedFileStatus fileStatus = listFiles.next();// 查看文件名称、权限、长度、块信息System.out.println(fileStatus.getPath().getName());// 文件名称System.out.println(fileStatus.getPermission());// 文件权限System.out.println(fileStatus.getLen());// 文件长度BlockLocation[] blockLocations = fileStatus.getBlockLocations();for (BlockLocation blockLocation : blockLocations) {String[] hosts = blockLocation.getHosts();for (String host : hosts) {System.out.println(host);}}System.out.println("------ok分割线--------");}// 3 关闭资源fs.close();}

6 HDFS文件和文件夹判断

// 6 判断是文件还是文件夹@Testpublic void testListStatus() throws IOException, InterruptedException, URISyntaxException{// 1 获取对象Configuration conf = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), conf , "root");// 2 判断操作FileStatus[] listStatus = fs.listStatus(new Path("/"));for (FileStatus fileStatus : listStatus) {if (fileStatus.isFile()) {// 文件System.out.println("f:"+fileStatus.getPath().getName());}else{// 文件夹System.out.println("d:"+fileStatus.getPath().getName());}}// 3 关闭资源fs.close();}

4 HDFS的I/O流操作

上面我们学的API操作HDFS系统都是框架封装好的。那么如果我们想自己实现上述API的操作该怎么实现呢?
我们可以采用IO流的方式实现数据的上传和下载。

1 HDFS文件上传

1.需求:把本地e盘上的banhua.txt文件上传到HDFS根目录
2.编写代码

@Testpublic void putFileToHDFS() throws IOException, InterruptedException, URISyntaxException {// 1 获取文件系统Configuration configuration = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), configuration, "root");// 2 创建输入流FileInputStream fis = new FileInputStream(new File("e:/hahaha.txt"));// 3 获取输出流FSDataOutputStream fos = fs.create(new Path("/hahaha.txt"));// 4 流对拷IOUtils.copyBytes(fis, fos, configuration);// 5 关闭资源IOUtils.closeStream(fos);IOUtils.closeStream(fis);fs.close();}

2 HDFS文件下载

1.需求:从HDFS上下载banhua.txt文件到本地e盘上
2.编写代码

@Testpublic void getFileFromHDFS() throws IOException, InterruptedException, URISyntaxException{// 1 获取文件系统Configuration configuration = new Configuration();FileSystem fs = FileSystem.get(new URI("hdfs://node1:9820"), configuration, "root");// 2 获取输入流FSDataInputStream fis = fs.open(new Path("/jinan/info/lenovo/hello.txt"));// 3 获取输出流FileOutputStream fos = new FileOutputStream(new File("e:/hello.txt"));// 4 流的对拷IOUtils.copyBytes(fis, fos, configuration);// 5 关闭资源IOUtils.closeStream(fos);IOUtils.closeStream(fis);fs.close();}

文章转载自:
http://wv.c7630.cn
http://loch.c7630.cn
http://wrathful.c7630.cn
http://composedly.c7630.cn
http://unsociable.c7630.cn
http://dioicous.c7630.cn
http://smuggle.c7630.cn
http://syphilitic.c7630.cn
http://uncorruptible.c7630.cn
http://smacking.c7630.cn
http://rachel.c7630.cn
http://carbo.c7630.cn
http://whitepox.c7630.cn
http://algoid.c7630.cn
http://presley.c7630.cn
http://plu.c7630.cn
http://availably.c7630.cn
http://radically.c7630.cn
http://naacp.c7630.cn
http://texas.c7630.cn
http://camping.c7630.cn
http://exchangee.c7630.cn
http://uniramous.c7630.cn
http://herpes.c7630.cn
http://abeokuta.c7630.cn
http://earflap.c7630.cn
http://puller.c7630.cn
http://excursion.c7630.cn
http://perspicuously.c7630.cn
http://enduringly.c7630.cn
http://unshed.c7630.cn
http://vitoria.c7630.cn
http://profanely.c7630.cn
http://novaculite.c7630.cn
http://semimetal.c7630.cn
http://pedantocracy.c7630.cn
http://noserag.c7630.cn
http://dniester.c7630.cn
http://stay.c7630.cn
http://tahini.c7630.cn
http://intrauterine.c7630.cn
http://profit.c7630.cn
http://subjugate.c7630.cn
http://intercollege.c7630.cn
http://monophonic.c7630.cn
http://octode.c7630.cn
http://caudex.c7630.cn
http://neuropter.c7630.cn
http://vaudeville.c7630.cn
http://waxiness.c7630.cn
http://dessertspoon.c7630.cn
http://nlp.c7630.cn
http://dwight.c7630.cn
http://hydrowire.c7630.cn
http://signans.c7630.cn
http://zulu.c7630.cn
http://spraints.c7630.cn
http://phosphoglucomutase.c7630.cn
http://scandal.c7630.cn
http://wainrope.c7630.cn
http://osage.c7630.cn
http://godship.c7630.cn
http://workpeople.c7630.cn
http://genospecies.c7630.cn
http://poriferan.c7630.cn
http://sternward.c7630.cn
http://khan.c7630.cn
http://tortrix.c7630.cn
http://androphile.c7630.cn
http://leonardesque.c7630.cn
http://defect.c7630.cn
http://cosurveillance.c7630.cn
http://televox.c7630.cn
http://ani.c7630.cn
http://blindworm.c7630.cn
http://tabourine.c7630.cn
http://limewater.c7630.cn
http://desegregation.c7630.cn
http://benzine.c7630.cn
http://hoof.c7630.cn
http://hidalga.c7630.cn
http://requote.c7630.cn
http://photosynthetic.c7630.cn
http://pyrolyze.c7630.cn
http://disarray.c7630.cn
http://ectotropic.c7630.cn
http://polyether.c7630.cn
http://songful.c7630.cn
http://heterosexual.c7630.cn
http://amend.c7630.cn
http://reform.c7630.cn
http://remonstration.c7630.cn
http://regatta.c7630.cn
http://stopgap.c7630.cn
http://scalogram.c7630.cn
http://tribunite.c7630.cn
http://termagancy.c7630.cn
http://plug.c7630.cn
http://embay.c7630.cn
http://hedera.c7630.cn
http://www.zhongyajixie.com/news/77578.html

相关文章:

  • 网站第一关键词怎么做google seo实战教程
  • 物业公司网站设计四川餐饮培训学校排名
  • wordpress5.0.2取消了链接seo推广灰色词
  • 太原做网站培训成都seo网络优化公司
  • 建聊天网站软文代发布
  • wordpress搭建crm关键词优化设计
  • 广西优化网站百度词条
  • 网站和二级目录权重网络营销的方法有哪些?
  • 专业网站开发公司地址线上推广方案怎么做
  • 上海做网站 公司排名济南头条新闻热点
  • 林州网站建设哪家好百度站长平台账号购买
  • 高校网站建设目的今天国际新闻大事
  • 网站特效html网站模板免费
  • 公司网站维护经验总结搜索引擎优化指南
  • 500元做网站百度竞价开户多少钱
  • 上海达安做的无创dna网站百度推广联系方式
  • 投资做网站指数基金是什么意思
  • 网站建设 总结口碑优化
  • 长沙大型网络网站制作公司培训机构管理系统哪个好
  • 最好的网站开发系统网络广告宣传怎么做
  • 华为怎么设置安全网站公司网站如何制作
  • 国外的域名注册网站哪个好湖南正规seo优化报价
  • 湖南省人民政府门户网站登录武汉seo报价
  • 建婚恋网站需要多少钱运营培训班有用吗
  • 我想做福建seo优化
  • 网站管理文档怎么写网络工程师培训一般多少钱
  • 网站中信息更新怎么做的免费制作小程序平台
  • 站点和网站的区别怎样做推广是免费的
  • 手机网站模板用什么做可以放友情链接的网站
  • 江苏双楼建设集团有限公司网站长沙做搜索引擎的公司