Java 如何创建没有随机数的临时文件

Java 如何创建没有随机数的临时文件,java,Java,我需要发送pdf文件作为附件与邮件。这是每2小时运行一次的调度程序作业。直接来说,它不接受给定的文件未发现异常,所以我想我把它放在临时目录中并从那里发送。此作业在JBoss服务器上运行 File temp = null; String tDir = System.getProperty("java.io.tmpdir") + "SupplierGuide";try { temp = File.createTempFile(tDir, ".pdf"); final InputStr

我需要发送pdf文件作为附件与邮件。这是每2小时运行一次的调度程序作业。直接来说,它不接受给定的文件未发现异常,所以我想我把它放在临时目录中并从那里发送。此作业在JBoss服务器上运行

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();
}

我在ApacheTomcat7.0.65Web服务器上通过servlet尝试了这一点。此例程还使用Java7和ApacheCommons IO Utils(
Commons-IO-1.3.2.jar


我想要文件名“SupplierGuide.pdf”。你从哪里得到一个随机数?为什么不直接取你想要的文件名呢?(
temp=new File(“任意名称”);
)顺便说一句。有趣的代码格式化方法。事实上,第一个问题是……我在服务器上得到java.io.FileNotFoundException,而在本地调试时它工作正常。我有一个PDF文件,它是jar本身的一部分。此PDF将通过邮件发送。这个jar将通过kjb作业在服务器上运行。为了解决第一个问题,我创建了临时文件。现在名称有随机数。
private void createUserGuideInTempFolder()
        throws IOException {
    String inputFileName = "N:\\TestData\\user-guide.pdf";
    String baseName = FilenameUtils.getBaseName(inputFileName);
    String extension = FilenameUtils.getExtension(inputFileName);
    Path tempFilePath = Files.createTempFile(baseName, extension);
    Path inputFilePath = Paths.get(inputFileName);

    InputStream inStream = Files.newInputStream(inputFilePath);
    byte [] fileBytes = IOUtils.toByteArray(inStream);
    tempFilePath = Files.write(tempFilePath, fileBytes);
    System.out.println(inputFilePath);
    // Prints input file: N:\TestData\user-guide.pdf
    System.out.println(tempFilePath);
    // Prints temp file: N:\apache-tomcat-7.0.65\temp\user-guide3642635958536288074pdf

    Path newTempFilePath = Paths.get(tempFilePath.getParent().toString(),
                    inputFilePath.getFileName().toString());    
    newTempFilePath = Files.move(tempFilePath, newTempFilePath);
    System.out.println(newTempFilePath);
    // Prints result file in temp: N:\apache-tomcat-7.0.65\temp\user-guide.pdf
}