Java Random Temp File getRandomTempFile()

Here you can find the source of getRandomTempFile()

Description

get Random Temp File

License

LGPL

Declaration

public static File getRandomTempFile() throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class Main {
    private static final String JAVA_IO_TMP_DIR = "java.io.tmpdir";

    public static File getRandomTempFile() throws IOException {
        String tempName = UUID.randomUUID().toString().replaceAll("-", "");
        //Create new temp file under OS's temp folder with a random name
        File tempFile = new File(System.getProperty(JAVA_IO_TMP_DIR) + tempName + ".tmp");
        if (!tempFile.createNewFile()) {
            throw new IOException("Can not create temp file :" + tempFile.getParent());
        }/*from w w  w  . j av a 2  s.  c o m*/
        return tempFile;

    }
}

Related

  1. getRandomTemporaryFolder(String prefix, String suffix)
  2. getRandomTmpFolder()