Java examples for Big Data:HDF
Demonstrates reading of a file from Distributed HDFS.
import java.net.URI; import java.util.Scanner; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DistributedFileSystem; public class HDFSJavaAPIReadDemo { public static void main(String[] args) throws Exception { System.setProperty("HADOOP_USER_NAME", "root"); final Path path = new Path("tutorials-links.txt"); try (final DistributedFileSystem dFS = new DistributedFileSystem() { {//from w w w .j av a 2 s. c om initialize(new URI("hdfs://192.168.1.8:50050"), new Configuration()); } }; final FSDataInputStream streamReader = dFS.open(path); final Scanner scanner = new Scanner(streamReader);) { System.out.println("File Contents: "); while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } } } }