apache hadoop file system cat - Java Big Data

Java examples for Big Data:Hadoop

Description

apache hadoop file system cat

Demo Code


import java.io.InputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

public class FilesystemCat {
    public static void main(String[] args) throws Exception {
        String url = "hdfs://neusoft-master:9000/user/root/test/demo1";
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(url), conf);
        InputStream in = null;//from   ww w  .  j  a va 2s.c  o m
        try {
            in = fs.open(new Path(url));
            IOUtils.copyBytes(in, System.out, 4096, false);
        } catch (Exception e) {
            IOUtils.closeStream(in);
        }
    }
}

Related Tutorials