Create a temporary directory - Java File Path IO

Java examples for File Path IO:File Permission

Description

Create a temporary directory

Demo Code

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
  public static void main(String[] args) {
    Path basedir = FileSystems.getDefault().getPath("C:/folder1/tmp/");
    String tmp_dir_prefix = "test_";
    try {//w ww. j  a  v  a  2  s  . c o m
      // create a tmp directory in the base dir
      Path tmp = Files.createTempDirectory(basedir, tmp_dir_prefix);
      System.out.println("TMP: " + tmp.toString());
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials