List of utility methods to do Temp File Create
File | createTempFile(@Nonnull String prefix, @Nonnull String suffix, @Nullable File parentDir) Creates a temporary file Random rand = new Random(); String parent = parentDir == null ? System.getProperty("java.io.tmpdir") : parentDir.getPath(); DecimalFormat fmt = new DecimalFormat("#####"); File result; do { result = new File(parent, prefix + fmt.format(Math.abs(rand.nextInt())) + suffix); } while (result.exists()); return result; ... |
File | createTempFile(final String file, final String ext) create Temp File File f = new File(file); String filename = f.getName(); if (filename == null) { filename = "export"; SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmm"); String date = formatter.format(new Date()); filename = filename + "_" + date + "_"; ... |
File | createTempFile(String oriFileName) create Temp File return new File(System.getProperty("java.io.tmpdir"), new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + "_" + new Random().nextInt(99999) + "_" + oriFileName); |
File | getTempFile() get Temp File File f = File.createTempFile("tmp", ".html", null); tempFiles.add(f); return f; |
File | getTempFile() get Temp File return File.createTempFile("temp", Long.toString(System.nanoTime())); |
File | getTempFile(File file) create a empty temp file at file's directory, temp file's name is based on file's name, i.e. File tempFile; while (true) { tempFile = new File(file.getParent(), file.getName() + ".tmp." + FILENAME_RANDOM.nextInt()); if (!tempFile.exists()) { if (!tempFile.createNewFile()) { throw new IOException(String.format("create %s failed", tempFile)); return tempFile; ... |
File | getTempFile(File parent, String fileName) Getting a temp file object in the directory in temporal directory which is referrenced by System.getProperty("java.io.tmpdir") . return new File(new File(getTempDirectory(), parent.getPath()), fileName); |
File | getTempFile(final File stackFile) get Temp File return new File("/tmp/" + stackFile.getName() + ".tmp"); |
File | getTempFile(final String directory, final String suffix, boolean autodelete) Creates a temporary file in the given directory, with the given suffix. int num = randomNumberGenerator.nextInt(Integer.MAX_VALUE); File file = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); while (file.exists()) { num = randomNumberGenerator.nextInt(Integer.MAX_VALUE); file = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); if (!file.createNewFile()) { throw new IOException("Failed to create file " + file.getAbsolutePath()); ... |
File | getTempFile(final String name) get Temp File return new File("temp" + File.separator + "test", name).getCanonicalFile(); |