hdfs文件的读取 (在eclipse中console输出)
package com.qf.a.b;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class hdfs {
public static void main(String[] args) throws IOException {
readFileToConsole("/input/a.txt");
}
public static void readFileToConsole(String pat) throws IOException {
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs://192.168.8.10:9000");
FileSystem fs = FileSystem.get(conf);
//String path = null;
//FSDataInputStream fis = fs.open(new Path(path));
FSDataInputStream fis = fs.open(new Path("/input/a.txt"));
IOUtils.copyBytes(fis, System.out, 4096, true);
}
}