hadoop的APIdemo 181202

通过java对hdfs文件的读取操作

public class apidemo {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();//通过configuration 找到class path  下的 core_site   hdfs_site 配置文件 和各种jar包
        FileSystem fs = FileSystem.get(conf); 

//先创建一个file system  并调用get方法  发现需要传configuration  创建configuration conf


        Path f = new Path("hdfs://master:9000/wordcount/test1.txt");
        FSDataInputStream in = fs.open(f);

//用fs调用open方法 打开流  发现需要传path  创建一个path 也就是你要打开所需要流的路径
        IOUtils.copyBytes(in, System.out, 2048,true);

//调用io工具类进行输出操作
    }
}
 

猜你喜欢

转载自blog.csdn.net/xutao_ccu/article/details/84726590