yekang

HDFS 입출력 예제 본문

빅데이터

HDFS 입출력 예제

예캉 2018. 1. 25. 12:05


SingleFileWrite.java



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package edu.pusan.ch03;
 
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
 
public class SingleFileWrite {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        if(args.length!=2){
            System.err.println("Usage: ");
            System.exit(2);
        }
        
        try{
            //파일 시스템 제어 객체 생성
            Configuration conf = new Configuration();
            FileSystem hdfs = FileSystem.get(conf); //hdfs
            //경로 체크
            Path path = new Path(args[0]);
            if(hdfs.exists(path)){
                hdfs.delete(path, true);
            }
            //파일 저장.72p2번
            FSDataOutputStream outStream = hdfs.create(path);
            outStream.writeUTF(args[1]);
            outStream.close();
            
            } catch(Exception e){
                e.printStackTrace();
            }
        
    }
 
}
 
cs




잘 출력되는 모습이다.

'빅데이터' 카테고리의 다른 글

[데이터 전처리 대전] 리뷰  (0) 2019.12.15
WordCount 구현 in JAVA  (0) 2018.01.25
하둡1 wordcount -하늘과 바람과 별과 시 (1948)  (0) 2018.01.25
하둡1 wordcount - 문재인 대통령  (0) 2018.01.24
빅데이터란?  (0) 2017.07.03
Comments