Java Temp Directory Get getTempDir(String prefix)

Here you can find the source of getTempDir(String prefix)

Description

get Temp Dir

License

Open Source License

Declaration

public static File getTempDir(String prefix) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 EclipseSource and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w w  w .  ja  v a 2s.  com
 *    EclipseSource - initial API and implementation
 ******************************************************************************/

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

public class Main {
    public static File getTempDir(String prefix) {
        String baseTempDir = System.getProperty("java.io.tmpdir");
        File tempDir = new File(baseTempDir, prefix + "-temp");
        File result = connonicalize(tempDir);
        result.deleteOnExit();
        return result;
    }

    private static File connonicalize(File directory) {
        File result;
        try {
            result = directory.getCanonicalFile();
        } catch (IOException ioe) {
            String msg = "Failed to obtain cannonical path: " + directory.getAbsolutePath();
            throw new RuntimeException(msg, ioe);
        }
        return result;
    }
}

Related

  1. getTempDir(final String directory, final String prefix, boolean autodelete)
  2. getTempDir(Object fileID, String fileName)
  3. getTempDir(String desc)
  4. getTempDir(String name, String prefix, File parentDir)
  5. getTempDir(String path)
  6. getTempDir(String suffix)
  7. getTempDirectory()
  8. getTempDirectory()
  9. getTempDirectory()