1. 코드 작성

import java.io.InputStream;
import java.net.URL;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;
public class FileRead {
    static {
        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
    }
    public static void main(String[] args) throws Exception {
        InputStream fileInputStream = null;
        try {
            fileInputStream = new URL(args[0]).openStream();
            IOUtils.copyBytes(fileInputStream, System.out, 4096, false);
        } finally {
            IOUtils.closeStream(fileInputStream);
        }
    }
}

 

2. compile 및 실행

cdh 기준으로 작성

 

1) compile

javac -cp `hadoop classpath`  FileRead.java -d build -Xlint

 

2) jar packing

jar -cvf file_read.jar -c build/ .

 

3) 실행

export HADOOP_CLASSPATH=file_read.jar

hadoop FileRead hdfs://cluster1.test.co.kr:8020/tmp/test.csv

 

'NoSQL > Hadoop' 카테고리의 다른 글

yarn command  (0) 2019.07.09
hdfs admin 명령어  (0) 2019.06.27
erasure encoding  (0) 2019.06.27
HDFS DataNode내 Disk 데이터 밸런싱  (0) 2019.06.27
HDFS DataNode 데이터 밸런싱  (0) 2019.06.27

+ Recent posts