Java Temp File Create nio createTemporaryFile(String extension)

Here you can find the source of createTemporaryFile(String extension)

Description

create Temporary File

License

Open Source License

Declaration

static File createTemporaryFile(String extension) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.UUID;

public class Main {
    private static final LinkedList<File> tempFiles = new LinkedList<>();

    static File createTemporaryFile(File basePath, String extension) {
        Path p = basePath == null
                ? Paths.get(System.getProperty("java.io.tmpdir"),
                        "soundclip-" + UUID.randomUUID().toString() + extension)
                : Paths.get(basePath.getAbsolutePath(), "soundclip-" + UUID.randomUUID().toString() + extension);

        File f = p.toFile();/*  w  ww  . j a  va 2s  . c om*/

        tempFiles.add(f);
        return f;
    }

    static File createTemporaryFile(String extension) {
        return createTemporaryFile(null, extension);
    }
}

Related

  1. createTempFile(final Object forObject)
  2. createTempFile(final String name)
  3. createTempFile(String contents)
  4. createTempFile(String name)
  5. createTempFile(String name, String extension, String[] lines)
  6. createTemporaryFileFromURL(final URL url)