Creating a Temporary Directory - Java File Path IO

Java examples for File Path IO:Directory Create

Description

Creating a Temporary Directory

Demo Code

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

public class Main {
  public static void main(String[] args) {
    String tmp_dir_prefix = "nio_";
    try {/*from w  ww .j  a  va  2  s  .c  o  m*/
      // passing null prefix
      Path tmp_1 = Files.createTempDirectory(null);
      System.out.println("TMP: " + tmp_1.toString());

      // set a prefix
      Path tmp_2 = Files.createTempDirectory(tmp_dir_prefix);
      System.out.println("TMP: " + tmp_2.toString());
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Related Tutorials