Hadoop 使用FileSystem API 读取数据

代码:

package com.hadoop;

import java.io.IOException;
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 IOException {
		String uri = args[0];
		
		Configuration config = new Configuration();
		
		FileSystem fs = FileSystem.get(URI.create(uri), config);
				
		InputStream in = null;
		try {
			in = fs.open(new Path(uri));
			IOUtils.copyBytes(in, System.out, 4096,false);
		} finally {
			IOUtils.closeStream(in);
		}
	}
}

  hadoop中执行:

 

posted @ 2016-06-15 16:33  依稀|.мīss.чou  阅读(254)  评论(0编辑  收藏  举报