HDFS -- hadoop的FileSystem样例
2021/12/3 6:06:35
本文主要是介绍HDFS -- hadoop的FileSystem样例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
样例
package pers.aishuang.flink.streaming.task; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URI; public class FileSystemTest { public static void main(String[] args) throws Exception{ //Configuration conf = new Configuration(); //conf.set("fs.defaultFS","hdfs://node01:8020/"); //FileSystem fileSystem = FileSystem.get(conf); FileSystem fileSystem = FileSystem.get(new URI("hdfs://node01:8020"), new Configuration(),"root"); RemoteIterator<LocatedFileStatus> itr = fileSystem.listFiles(new Path("/test/"), true); Path outPath = new Path("/fileSystemData02/"); BufferedWriter writer; FSDataOutputStream out = fileSystem.create(outPath); FSDataInputStream in; while (itr.hasNext()){ LocatedFileStatus next = itr.next(); Path path = next.getPath(); in = fileSystem.open(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8")); writer = new BufferedWriter(new OutputStreamWriter(out, "utf-8")); String line; while((line = reader.readLine()) != null) { writer.write(line); writer.newLine(); writer.flush(); } in.close(); } out.close(); } }
结果:
这篇关于HDFS -- hadoop的FileSystem样例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2023-05-13Windows下hadoop环境搭建之NameNode启动报错
- 2023-04-14hadoop伪分布式集群的安装(不是单机版)
- 2022-12-05Hadoop生态系统—数据仓库Hive的安装
- 2022-11-02Win10搭建Hadoop环境
- 2022-10-19Hadoop生态系统(数据仓库Hive的安装)
- 2022-10-03Hadoop、storm和Spark Streaming简单介绍
- 2022-10-03胖虎的Hadoop笔记——Hadoop的伪分布式部署
- 2022-09-11Ubuntu搭建全分布式Hadoop
- 2022-09-11Ubuntu搭建全分布式Hadoop
- 2022-09-09Ubuntu下安装伪分布式HADOOP遇到的一些问题