Java Path Create nio createTempPath(String prefix, String suffix)

Here you can find the source of createTempPath(String prefix, String suffix)

Description

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

License

Open Source License

Parameter

Parameter Description
prefix The prefix string to be used in generating the file's name; must be at least three characters long
suffix The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used

Exception

Parameter Description
IllegalArgumentException - If the prefix argument contains fewer than three characters
IOException - If a file could not be created
SecurityException - If a security manager exists and itsjava.lang.SecurityManager.checkWrite(java.lang.String) method does not allow afile to be created

Return

the path to the newly created file that did not exist before this method was invoked

Declaration

public static Path createTempPath(String prefix, String suffix) throws IOException 

Method Source Code

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

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

import java.nio.file.Path;

public class Main {
    /**//w w  w .ja v a  2  s.  c  om
     * Creates an empty file in the default temporary-file directory, using the given prefix and
     * suffix to generate its name. The deleteOnExit property is set by default.
     *
     * @param prefix
     *            The prefix string to be used in generating the file's name; must be at least three
     *            characters long
     * @param suffix
     *            The suffix string to be used in generating the file's name; may be null, in which
     *            case the suffix ".tmp" will be used
     * @return the path to the newly created file that did not exist before this method was invoked
     *
     * @throws IllegalArgumentException
     *             - If the prefix argument contains fewer than three characters
     * @throws IOException
     *             - If a file could not be created
     * @throws SecurityException
     *             - If a security manager exists and its
     *             java.lang.SecurityManager.checkWrite(java.lang.String) method does not allow a
     *             file to be created
     *
     * @see {@link File#createTempFile(String, String)}
     */
    public static Path createTempPath(String prefix, String suffix) throws IOException {
        File tempFile = File.createTempFile(prefix, suffix);
        tempFile.deleteOnExit();
        return tempFile.toPath();
    }

    /**
     * Creates an empty file in the default temporary-file directory, using the given prefix and
     * suffix to generate its name. The deleteOnExit property is set by default.
     *
     * @param prefix
     *            The prefix string to be used in generating the file's name; must be at least three
     *            characters long
     * @param suffix
     *            The suffix string to be used in generating the file's name; may be null, in which
     *            case the suffix ".tmp" will be used
     * @return the path to the newly created file that did not exist before this method was invoked
     *
     * @throws IllegalArgumentException
     *             - If the prefix argument contains fewer than three characters
     * @throws IOException
     *             - If a file could not be created
     * @throws SecurityException
     *             - If a security manager exists and its
     *             java.lang.SecurityManager.checkWrite(java.lang.String) method does not allow a
     *             file to be created
     *
     * @see {@link File#createTempFile(String, String)}
     */
    public static File createTempFile(String prefix, String suffix) throws IOException {
        File tempFile = File.createTempFile(prefix, suffix);
        tempFile.deleteOnExit();
        return tempFile;
    }
}

Related

  1. createSymlink(String targetPathStr, File symlinkFile)
  2. createTempDirectory(final String path, final String prefix)
  3. createTempDirectory(Path dir, String prefix)
  4. createTempFile(Path baseDir, String prefix, String suffix)
  5. createTempFilePath(final String stem, final String extension)
  6. createTmpDir(Path tmpDir, String prefix)
  7. createUniqueFilePath(final String directory, final String baseName, final String suffix)
  8. createUrlQuietly(Path path)
  9. createZipArchive(final Path sourceDir, final Path destFile)