eclipse中访问hdfs时候问题总结(hadoop-2.7.1)

以以下代码为例:

import java.io.IOException;

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

public class ReadHdfsData {

	public static void read_output(String name){
		try{
			FileSystem fs=FileSystem.get(new Configuration());
			FSDataInputStream fsdata=fs.open(new Path(name));
			IOUtils.copyBytes(fsdata, System.out, 4096, false);
			IOUtils.closeStream(fsdata);
		}catch(IOException e){
		  e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
       ReadHdfsData.read_output("hdfs://localhost/user/cj/output/part-r-00000");
	}
}

一定要导入hadoop-2.7.1/share/hadoop/common/目录下hadoop-common-2.7.1.jar,   以及/usr/local/hadoop-2.7.1/share/hadoop/hdfs/目录下hadoop-hdfs-2.7.1.jar
core-site.xml 与hdfs-site.xml一定要放入java项目的bin 目录下

你可能感兴趣的:(eclipse中访问hdfs时候问题总结(hadoop-2.7.1))