//通过FileSystem API读取数据
//这里是以FileSystem以标准输出格式显示Hadoop文件中的文件
package com;
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{
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
String uri = args[0];
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
InputStream in = null;
try{
in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 4096, false);
}finally{
IOUtils.closeStream(in);
}
}
}
时间: 2024-12-19 12:05:47