本文整理汇总了Java中org.apache.poi.hmef.Attachment类的典型用法代码示例。如果您正苦于以下问题:Java Attachment类的具体用法?Java Attachment怎么用?Java Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Attachment类属于org.apache.poi.hmef包,在下文中一共展示了Attachment类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractAttachments
import org.apache.poi.hmef.Attachment; //导入依赖的package包/类
/**
* Extracts all the message attachments to the supplied directory
*/
public void extractAttachments(File dir) throws IOException {
int count = 0;
for(Attachment att : message.getAttachments()) {
count++;
// Decide what to call it
String filename = att.getLongFilename();
if(filename == null || filename.length() == 0) {
filename = att.getFilename();
}
if(filename == null || filename.length() == 0) {
filename = "attachment" + count;
if(att.getExtension() != null) {
filename += att.getExtension();
}
}
// Save it
File file = new File(dir, filename);
FileOutputStream fout = new FileOutputStream(file);
fout.write( att.getContents() );
fout.close();
}
}