2013-05-31 9 views
0

a에서 추출한 이미지를 저장하려고합니다. doc 파일을 임시 폴더에 저장합니다. 폴더를 만들 수 있었고 이미지도 추출되었지만 폴더에 저장하는 방법을 모릅니다. 도와 드릴까요?Java로 특정 폴더에 그림 저장

이 지금까지 수행 된 것입니다 :

private static void documentImagesCapture(HWPFDocument doc) { 
    PicturesTable picturesTable = doc.getPicturesTable(); 
    List<Picture> allPictures = picturesTable.getAllPictures(); 
    System.out.println("Number of pictures in the document: "+allPictures.size()); 

    if (allPictures.size()>0){ 

     final Path folderPath = Paths.get("src/test/resources/test-documents/"); 
     final Path tmpDir; 

     try { 
      // Create tmp folder 
      tmpDir = Files.createTempDirectory(folderPath, null); 
      System.out.println("This is a temporary folder: " + tmpDir); 

      // Extract a Picture file 
      for (Picture pic : allPictures){ 
       System.out.println("this is the picture that I want to save : " + pic); 
       //Save pic in tmpDir??????? 
      } 

     } catch (IOException e) { 
      System.err.println(">>>>>>>>> ERROR >>>>>>>>> WordDocSplitter.documentImagesCapture()"); 
      e.printStackTrace(); 
     } 
    } 
} 

감사


감사 데이비드 !!!! 나는이 방법으로 해결 :

for (Picture pic : allPictures){ 
    File newFilePic = new File(pic.suggestFullFileName()); 
    pic.writeImageContent(new DataOutputStream(new FileOutputStream(newFilePic))); 
    FileUtils.copyFileToDirectory(newFilePic, new File(tmpDir.toString())); 
    FileUtils.forceDelete(newFilePic); 
} 

답변

1

는 그림 개체의 writeImageContent 방법을 사용합니다. 문서 here.

writeImageContent

공공 무효 writeImageContent (java.io.OutputStream에 아웃) 는

때 java.io.IOException

지정된 OutputStream에 사진의 내용 바이트를 기입합니다. 이 스트림에 직접 그림 바이트를 쓰고, 표현을 으로 뚜렷한 바이트 배열로 생략 할 필요가있을 때 유용합니다. 파라미터 : out - 기입하는 스트림 예외 : java.io.IOException - 예외가 발생했을 경우 지정된 출력