HDFS数据读写过程-Hadoop,Hive,Hbase等框架详解

时间:2024-05-16 04:04:09
【文件属性】:

文件名称:HDFS数据读写过程-Hadoop,Hive,Hbase等框架详解

文件大小:3.06MB

文件格式:PPT

更新时间:2024-05-16 04:04:09

Hadoop Hive Spark Hbase

HDFS数据读写过程 读取文件 import java.io.BufferedReader; import java.io.InputStreamReader; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.FSDataInputStream; public class Reader { public static void main(String[] args) { try { Configuration conf = new Configuration(); conf.set("fs.defaultFS","hdfs://localhost:9000"); conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem"); FileSystem fs = FileSystem.get(conf); Path file = new Path("test"); FSDataInputStream getIt = fs.open(file); BufferedReader d = new BufferedReader(new InputStreamReader(getIt)); String content = d.readLine(); //读取文件一行 System.out.println(content); d.close(); //关闭文件 fs.close(); //关闭hdfs } catch (Exception e) { e.printStackTrace(); } } }  }


网友评论