Java Temp File Create getTempFile(String config)

Here you can find the source of getTempFile(String config)

Description

get Temp File

License

Open Source License

Declaration

public static File getTempFile(String config) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 cnfree.// w  w w. j a va  2 s. c  o  m
 * 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:
 *  cnfree  - initial API and implementation
 *******************************************************************************/

import java.io.File;

public class Main {
    public static File getTempFile(String config) {
        return getTempFile(config, ".xml");
    }

    public static File getTempFile(String config, String suffix) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        String filePath = System.getProperty("java.io.tmpdir") + System.currentTimeMillis() + "\\"
                + config.substring(config.lastIndexOf('/') + 1, config.lastIndexOf('.')) + suffix;
        File configFile = new File(filePath);
        if (!configFile.exists()) {
            if (!configFile.getParentFile().exists()) {
                configFile.getParentFile().mkdirs();
            }
        }
        return configFile;
    }
}

Related

  1. getTempFile(File file)
  2. getTempFile(File parent, String fileName)
  3. getTempFile(final File stackFile)
  4. getTempFile(final String directory, final String suffix, boolean autodelete)
  5. getTempFile(final String name)
  6. getTempFile(String extension)
  7. getTempFile(String fileId)
  8. getTempFile(String filePrefix, boolean deleteOnExit)
  9. getTempFile(String name)