Here you can find the source of getTempDirectory(String applicationName)
Parameter | Description |
---|---|
applicationName | The name of the application |
public static String getTempDirectory(String applicationName)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**/* w w w. j a v a 2 s .c o m*/ * Returns a temporary directory for a given application * * @param applicationName * The name of the application * @return The requested path. */ public static String getTempDirectory(String applicationName) { String tempDir = getApplicationDataDirectory(applicationName) + "/temp/"; File tempDirFile = new File(tempDir); if (!tempDirFile.exists()) { // Create it tempDirFile.mkdirs(); } return tempDirFile.getAbsolutePath() + File.separatorChar; } /** * This method finds the application data directory and creates (if it * doesn't exist) the directory corresponding to the application. (based on * the applicationName parameter) Under Linux, a directory is created in the * home of the user named .applicationName under windows, the directory is * creates in %APPDATA%/Intel/applicationName. * * @param applicationName * The name of the application * @return The string representing the created directory. */ public static String getApplicationDataDirectory(String applicationName) { String os = getOsName(); String appDataPath = getApplicationDataDirectory(); String fileSeparator = System.getProperty("file.separator"); if (os.contains("Linux")) { appDataPath += fileSeparator + "." + applicationName; } else /* Windows */ { appDataPath += fileSeparator + "Intel" + fileSeparator + applicationName; } File appDataFile = new File(appDataPath); if (!appDataFile.exists()) { // Create it appDataFile.mkdirs(); } return (appDataFile.getPath() + File.separatorChar); } /** * Get the application data directory. * * @return The string representing the application data directory. */ public static String getApplicationDataDirectory() { String os = getOsName(); String appDataPath; if (os.contains("Linux")) { appDataPath = System.getProperty("user.home"); } else /* Windows */ { appDataPath = System.getenv("APPDATA"); } return (appDataPath + File.separatorChar); } /** * The name of the running OS * * @return */ public static String getOsName() { return System.getProperty("os.name"); } }