0

から抽出した画像を保存しようとしています。doc ファイルを一時フォルダーに保存します。作成できたフォルダーと画像も抽出されましたが、フォルダーに保存する方法がわかりません。手伝ってくれますか?

これまでに行われたことは次のとおりです。

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);
}
4

1 に答える 1