我需要将pdf文件作为附件随邮件一起发送。这是每2小时运行一次的调度程序作业。直接地,它并不需要给文件未找到异常,所以我认为我将其放入temp目录并从那里发送。该作业在JBoss Server上运行。
File temp = null;
String tDir = System.getProperty("java.io.tmpdir") + "SupplierGuide";try
{
temp = File.createTempFile(tDir, ".pdf");
final InputStream inputStream = SendNotificationToContacts.class.getClassLoader()
.getResourceAsStream(result.getProperty("supplier.guide"));
IOUtils.copy(inputStream, new FileOutputStream(temp));
}catch(
Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:-1)
我从servlet在Apache Tomcat 7.0.65 Web服务器上尝试了此操作。此例程还使用Java 7和Apache Commons IO Utils(transform:translatez(0);
-webkit-transform:translatez(0);
)。
commons-io-1.3.2.jar