gpt4 book ai didi

java - 如何从 pst 文件获取帖子附件

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:11 26 4
gpt4 key购买 nike

我正在使用 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 - 如何从 pst 文件获取帖子附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25423005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com