Java Path Relative getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete)

Here you can find the source of getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete)

Description

get Relative Temporary Filename

License

Open Source License

Declaration

static synchronized public String getRelativeTemporaryFilename(String directory, String suffix,
            boolean autodelete) throws IOException 

Method Source Code

//package com.java2s;
/*/* ww w . ja  va 2 s  .c  om*/
 * Copyright (c) 2011, Marc R?ttig.
 *
 * This file is part of GenericKnimeNodes.
 * 
 * GenericKnimeNodes is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

import java.util.Random;

public class Main {
    static private Random rng = new Random();

    static synchronized public String getRelativeTemporaryFilename(String directory, String suffix,
            boolean autodelete) throws IOException {

        int num = Math.abs(rng.nextInt());
        File f = new File(directory + File.separator + String.format("%06d.%s", num, suffix));
        while (f.exists()) {
            num = Math.abs(rng.nextInt());
            f = new File(directory + File.separator + String.format("%06d.%s", num, suffix));
        }
        f.createNewFile();

        if (autodelete)
            f.deleteOnExit();

        return f.getName();
    }
}

Related

  1. getRelativeLink(File target, File base)
  2. getRelativeName(File file, File root)
  3. getRelativeName(final File directory, final File file)
  4. getRelativeName(final File file)
  5. getRelativeParentDirectory(File base, File file)
  6. getRelativeUnixPath(File baseDir, File refFile)
  7. makeRelativePath(File from, File to)
  8. makeRelativePath(File parent, File file)
  9. makeRelativePath(IPath path, IPath relativeTo)