hdfs read file java
Configuration conf = new Configuration();
conf.addResource(new Path("C:\\hadoop-3.1.0\\etc\\hadoop\\core-site.xml"));
conf.addResource(new Path("C:\\hadoop-3.1.0\\etc\\hadoop\\hdfs-site.xml"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String filePath = "hdfs://localhost:9000/directory/file.txt";
Path path = new Path(filePath);
FileSystem fs = path.getFileSystem(conf);
FSDataInputStream inputStream = fs.open(path);
System.out.println(inputStream.available());
String line = null;
while((line = inputStream.readLine()) != null) {
System.out.println(line);
}
fs.close();