Java Random File getRandomFile(String testName)

Here you can find the source of getRandomFile(String testName)

Description

get Random File

License

Apache License

Declaration

public static String getRandomFile(String testName) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static String getRandomFile(String testName) throws Exception {

        File parent = getTestDir();
        File result = new File(parent, getRandomFileName(testName));
        return result.getCanonicalPath();
    }//  w  w w . j  a va  2 s  .  c om

    public static File getTestDir() {

        File currentDir = new File(System.getProperty("user.dir"));
        if (!currentDir.exists()) {
            currentDir = new File(".");
        }

        String sep = File.separator;
        File testDir = new File(currentDir, "dist" + sep + "testresults"
                + sep + "test_temp_dir");
        testDir.mkdirs();

        return testDir;

    }

    public static String getRandomFileName(String testName) {
        return testName + System.currentTimeMillis() + "_" + Math.random();
    }
}

Related

  1. getRandomFile(String dir)
  2. getRandomFilename(String filePath)
  3. getRandomFilename(String prefix, String sufix)
  4. getRandomFilenameInDirectory(File rootFolder)