首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Pst文件中获取pst附件

如何从Pst文件中获取pst附件
EN

Stack Overflow用户
提问于 2014-08-21 17:38:40
回答 1查看 258关注 0票数 1

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

代码语言:javascript
复制
    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();
   }

我有这样的错误:

代码语言:javascript
复制
  Caused by: java.io.FileNotFoundException: Invalid file path
  at java.io.FileOutputStream.<init>(Unknown Source)
  at java.io.FileOutputStream.<init>(Unknown Source)
EN

回答 1

Stack Overflow用户

发布于 2014-09-09 11:33:28

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25423005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档