Hadoop API操作文件系统方法有哪些

发布时间:2021-12-09 15:52:32 作者:iii
来源:亿速云 阅读:120

这篇文章主要介绍“Hadoop API操作文件系统方法有哪些”,在日常操作中,相信很多人在Hadoop API操作文件系统方法有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Hadoop API操作文件系统方法有哪些”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

##Maven配置

<dependencies>        <dependency>            <groupId>org.apache.hadoop</groupId>            <artifactId>hadoop-client</artifactId>            <version>2.7.3</version>        </dependency>    </dependencies>

创建文件夹

Configuration config = new Configuration();        try {            FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000"),config);            boolean result =fs.mkdirs(new Path("/api/test"));            System.out.println(result);        }catch (Exception e){            e.printStackTrace();        }

####读取文件

FSDataInputStream in = fileSystem.open(new Path("/hadoop.txt")); IOUtils.copyBytes(in,System.out,1024);

####创建文件

FSDataOutputStream out = fileSystem.create(new Path("/hello.txt"));out.writeUTF("hello world");out.flush();out.close();

####重命名文件

fileSystem.rename(new Path("/hello.txt"),new Path("/new.txt"));

####拷贝本地文件到hdfs

fileSystem.copyFromLocalFile(new Path("./pom.xml"),new Path("/pom.xml"));

####下载hdfs文件到本地

fileSystem.copyToLocalFile(new Path("/hadoop.txt"),new Path("hadoop.txt"));

到此,关于“Hadoop API操作文件系统方法有哪些”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. Hadoop
  2. Hadoop快速入门

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hadoop api

上一篇:Hadoop文件读取的示例分析

下一篇:Hadoop与RPC通讯格式需求有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》