JAVA API 를 통 해 HDFS 에 파일 업로드

1171 단어 자바hadoop
hdfs 작업 주의사항
  •  가상 컴퓨터 방화벽 설정 닫 기
  • 프 록 시가 열 리 면 로 컬 모드 로 조정
  • core - site. xml 에서 설정 할 때 localhost 를 사용 하지 말고 가상 컴퓨터 IP 주 소 를 사용 해 야 합 니 다. 그렇지 않 으 면 가상 컴퓨터 hadop
  • 에 연결 할 수 없습니다.
  • 다음 과 같은 권한 이 부족 합 니 다. 사용자 권한 수정
  • 업로드 성공
  •  소스 코드
    public static void main(String[] args) throws Exception {
     
    //    SpringApplication.run(DemoApplication.class, args);
     
          String localSrc = "F:\\test.jpg";
          String destSrc = "hdfs://192.168.174.128:9000/hello.jpg";
     
          InputStream input = new BufferedInputStream(new FileInputStream(localSrc));
     
          Configuration conf = new Configuration();    //      
    //    conf.set("fs.defaultFS","hdfs://192.168.174.128:9000");
     
          URI uri = URI.create("hdfs://192.168.174.128:9000");   //  hdfsURI
     
          FileSystem hdfs = FileSystem.get( uri,conf);    //      
     
          OutputStream out = hdfs.create(new Path(destSrc), new Progressable() {
             @Override
             public void progress() {
                System.out.println("       ");
             }
          });
     
          IOUtils.copyBytes(input,out,4096,true);   //    
     
       }

    좋은 웹페이지 즐겨찾기