import java.io.InputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.IOUtils;
import java.io.*;
public class FileSystemCat
{
public static void main(String[] args) throws Exception {
String path = "hdfs://master:9000/robot/robot_vpe_20000-40000_join2.txt";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(path), conf);
FSDataInputStream hdfsInStream = fs.open(new Path(path));
InputStreamReader isr = new InputStreamReader(hdfsInStream, "utf-8");
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
maven pom.xml:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.4</version>
</dependency>
</dependencies>