【问题标题】:How can i get Pst Attchment from pst file如何从 pst 文件中获取帖子附件
【发布时间】:2014-08-21 09:38:40
【问题描述】:

我正在使用 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)

【问题讨论】:

  • 你检查过文件名是什么吗?并确保其中没有您的操作系统不喜欢的任何字符?
  • 好,是的,我只是添加 filename = filename.trim();它工作正常,谢谢

标签: java apache-tika pst


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-18
    • 2013-01-20
    • 2018-05-28
    相关资源
    最近更新 更多