使用FileSystem显示Hadoop文件系统中的文件
FileSystem的完整例子:
package com.digitalchina.test;import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URI;import java.net.URL;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 HadoopUrl {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubString uri="";InputStream in=null;Configuration conf=new Configuration();try {FileSystem fs=FileSystem.get(URI.create(uri), conf);in=fs.open(new Path(uri));IOUtils.copyBytes(in, System.out,4096, false);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{IOUtils.closeStream(in);}}}