java实现hadoop的cat命令

来源:互联网 发布:win32 api编程入门 编辑:程序博客网 时间:2024/06/04 00:38

本人理解的就是读取指定目录下文件输出出来

package com.hdfs;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;


import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


public class CatTest {
public static void main(String[] args) throws IOException {
Configuration conf=new Configuration();
FileSystem fs=FileSystem.get(conf);
Path f=new Path("/data/example/ydb/22.txt");



FSDataInputStream in=fs.open(f);

BufferedReader br=new BufferedReader(new InputStreamReader(in));
String line="";


while((line=br.readLine())!=null){
line=br.readLine();
System.out.println(line);
}
br.close();
}
}

0 0