generate Temp File - Java File Path IO

Java examples for File Path IO:File Operation

Description

generate Temp File

Demo Code


//package com.java2s;
import java.io.File;
import java.io.IOException;

public class Main {

    public static File generateTempFile(String prefix, String suffix) {
        File result = null;//  w w  w  . j  a v a2s . c o m
        try {
            result = File.createTempFile(prefix, suffix);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (result == null) {
            int rand = (int) (Math.random() * 0xFFFFFFFF);
            result = new File(prefix + String.format("_%X", rand) + suffix);
        }
        return result;

    }
}

Related Tutorials