빅데이터
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 |
잘 출력되는 모습이다.