Java Temp File Create createTempFile(final String file, final String ext)

Here you can find the source of createTempFile(final String file, final String ext)

Description

create Temp File

License

Open Source License

Declaration

private static File createTempFile(final String file, final String ext) throws IOException 

Method Source Code

//package com.java2s;
/*/*  w  w w .  j  a va2 s  . c o m*/
 * Copyright (c) 2010 Jardin Development Group <jardin.project@gmail.com>.
 * 
 * Jardin is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Jardin is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Jardin.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static File createTempFile(final String file, final String ext) throws IOException {

        File f = new File(file);
        String filename = f.getName();

        /* Aggancia la data al nome del file */
        if (filename == null) {
            filename = "export";
        }

        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmm");
        String date = formatter.format(new Date());
        // TODO effettuare la traslitterazione del nome del file
        filename = filename + "_" + date + "_";
        filename = filename.replace(' ', '.');
        filename = filename.replace('/', '.');
        // filename = filename.replace('\\', '.');
        filename = filename.toLowerCase();

        return File.createTempFile(filename, "." + ext, f.getParentFile());
    }
}

Related

  1. createTempFile(@Nonnull String prefix, @Nonnull String suffix, @Nullable File parentDir)
  2. createTempFile(String oriFileName)
  3. getTempFile()
  4. getTempFile()
  5. getTempFile(File file)