Here you can find the source of getTempPath()
public static String getTempPath()
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 www.isandlatech.com (www.isandlatech.com) * 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:/* w ww . j a v a 2 s .c o m*/ * ogattaz (isandlaTech) - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { private final static String FILE_EXT_TXT = "txt"; private final static String FILE_NAME_DUMMY = "dummy"; public static final String SYS_PROPERTY_TMPDIR = "java.io.tmpdir"; public static final String SYS_PROPERTY_USERDIR = "user.dir"; /** * @return */ public static String getTempPath() { String wPath = System.getProperty(SYS_PROPERTY_TMPDIR); if (wPath == null || wPath.length() == 0) { // System.out.println( // "Temporary directory is unknown ('java.io.tmpdir'), using directory used by 'File.createTempFile'." // ); wPath = getTempAbsolutePath(); if (wPath == null || wPath.length() == 0) { // System.out.println("'File.createTempFile' doesn't return directory, using current directory ('user.dir')."); wPath = System.getProperty(SYS_PROPERTY_USERDIR); } } return wPath; } /** * @return */ private static String getTempAbsolutePath() { String wPath = null; try { File wTempFile = File.createTempFile(FILE_NAME_DUMMY, FILE_EXT_TXT); wPath = wTempFile.getParent(); wTempFile.delete(); } catch (Exception e) { System.out.println(e.getMessage()); } return wPath; } }