Here you can find the source of getTempDirectory()
Parameter | Description |
---|---|
IOException | an exception |
public static String getTempDirectory() throws IOException
//package com.java2s; /******************************************************************************* * Copyright 2014 United States Government as represented by the * Administrator of the National Aeronautics and Space Administration. * All Rights Reserved./*from www . j ava2s. c o m*/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.io.File; import java.io.IOException; public class Main { /** * Return the directory where temporary files are created. * * @return the directory where temporary files are created. * @throws IOException */ public static String getTempDirectory() throws IOException { String tempDirectory = System.getProperty("java.io.tmpdir"); // works in JDK 1.4+ if (tempDirectory != null) { return tempDirectory; } File f = File.createTempFile("directory-finder", ".tmp"); // fall back for politeness f.delete(); return f.getParent(); } /** * Create a temporary file that will auto-delete when this VM terminates * * @param prefix * @param suffix * @return File * @throws IOException */ public static File createTempFile(String prefix, String suffix) throws IOException { File tempFile = File.createTempFile(prefix, suffix); tempFile.deleteOnExit(); return tempFile; } /** * Create a temporary file that will auto-delete when this VM terminates * * @param prefix * @param suffix * @param directory * @return File * @throws IOException */ public static File createTempFile(String prefix, String suffix, File directory) throws IOException { File tempFile = File.createTempFile(prefix, suffix, directory); tempFile.deleteOnExit(); return tempFile; } }