Java Temp File Create getTempFile(String filePrefix, boolean deleteOnExit)

Here you can find the source of getTempFile(String filePrefix, boolean deleteOnExit)

Description

get Temp File

License

Open Source License

Declaration

public static File getTempFile(String filePrefix, boolean deleteOnExit) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.IOException;

public class Main {
    public static File getTempFile(String filePrefix, boolean deleteOnExit) {
        String tempFileName = filePrefix + "-" + System.nanoTime();
        File tempFile = null;//from  w  w  w.ja  va2s  .com
        try {
            tempFile = File.createTempFile(tempFileName, ".txt");
            if (deleteOnExit) {
                tempFile.deleteOnExit();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return tempFile;
    }
}

Related

  1. getTempFile(final String directory, final String suffix, boolean autodelete)
  2. getTempFile(final String name)
  3. getTempFile(String config)
  4. getTempFile(String extension)
  5. getTempFile(String fileId)
  6. getTempFile(String name)
  7. getTempFile(String tmpdir)
  8. getTempFileDir()
  9. getTempFileFor(File file)