Specify the default directory where a temporary file is created - Java File Path IO

Java examples for File Path IO:File Permission

Description

Specify the default directory where a temporary file is created

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_file_prefix = "test_";
    String tmp_file_sufix = ".txt";

    try {//from ww w.  ja v  a 2s.  co m
      Path tmp_3 = Files.createTempFile(basedir, tmp_file_prefix,
          tmp_file_sufix);
      System.out.println("TMP: " + tmp_3.toString());
    } catch (IOException e) {
      System.err.println(e);
    }

  }
}

Result


Related Tutorials