Java examples for Big Data:Hadoop
apache hadoop file system cat
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); } } }