Here you can find the source of getTempFilePath(String name)
Parameter | Description |
---|---|
name | prefix of the file |
public static String getTempFilePath(String name)
//package com.java2s; /*/*from ww w . j a v a2s .co m*/ * Copyright (c) 2012 Diamond Light Source Ltd. * * 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 */ import java.io.File; public class Main { /** * * * @param name prefix of the file * @return a writable temporary file path */ public static String getTempFilePath(String name) { String file = ""; String tmpfilepath = System.getProperty("java.io.tmpdir") + File.separator; String tmpDiamondFilePath = "/dls/tmp/"; String username = System.getProperty("user.name"); File tmpDir = new File(tmpfilepath); // if tmp directory is writable boolean canWrite = tmpDir.canWrite(); if (canWrite) { File folderTmp = new File(tmpfilepath + username); if (!folderTmp.exists()) folderTmp.mkdir(); file = tmpfilepath + username + File.separator + "tmp_" + name; } else if (!canWrite) { File diamondFolderTmp = new File(tmpDiamondFilePath); if (diamondFolderTmp.canWrite()) { File diamondTmpUserFolder = new File(tmpDiamondFilePath + username); if (!diamondTmpUserFolder.exists()) { diamondTmpUserFolder.mkdir(); } file = tmpDiamondFilePath + username + File.separator + "tmp_" + name; } else { //TODO other case? } } return file; } }