1

我正在使用 java libpst 和 tika 从 pst 文件中提取元数据,我使用了以下代码:

    int numberOfAttachments = email.getNumberOfAttachments();
    for (int x = 0; x < numberOfAttachments; x++) {
    PSTAttachment attach = email.getAttachment(x);
   InputStream attachmentStream = attach.getFileInputStream();
   // both long and short filenames can be used for attachments
   String filename = attach.getLongFilename();
   if (filename.isEmpty()) {
        filename = attach.getFilename();
   }
   FileOutputStream out = new FileOutputStream(filename);
   // 8176 is the block size used internally and should give the best performance
   int bufferSize = 8176;
   byte[] buffer = new byte[bufferSize];
   int count = attachmentStream.read(buffer);
   while (count == bufferSize) {
        out.write(buffer);
        count = attachmentStream.read(buffer);
   }
   byte[] endBuffer = new byte[count];
   System.arraycopy(buffer, 0, endBuffer, 0, count);
   out.write(endBuffer);
   out.close();
   attachmentStream.close();
   }

我有这个错误:

  Caused by: java.io.FileNotFoundException: Invalid file path
  at java.io.FileOutputStream.<init>(Unknown Source)
  at java.io.FileOutputStream.<init>(Unknown Source)
4

1 回答 1

0

我也有同样的问题。因为文件名包含不需要的空格。所以我删除了它。

在您的代码中用于 filename = filename.trim();删除空格。

于 2014-09-09T03:33:27.960 回答