Source Code : Create temp file and directory

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Create temp file and directory


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

public class Test {

  public static void main(String[] args) throws Exception {

    Path rootDirectory = FileSystems.getDefault().getPath("C:/home/docs");

    Path tempDirectory = Files.createTempDirectory(rootDirectory, "");
    System.out.println("Temporary directory created successfully!");
    String dirPath = tempDirectory.toString();
    System.out.println(dirPath);
    Path tempFile = Files.createTempFile(tempDirectory, "", "");
    System.out.println("Temporary file created successfully!");
    String filePath = tempFile.toString();
    System.out.println(filePath);
  }
}

 

Thank with us