Java Files create directory

Description

Java Files create directory

import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
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 newPath = FileSystems.getDefault().getPath("C:\\home\\docs\\");
      try {//from w ww . ja v  a  2  s. c  o m
         Path myDirectory = Files.createDirectory(newPath);
         System.out.println("Directory created successfully!");
      } catch (FileAlreadyExistsException a) {
         System.out.println("Directory already exists!");
      } catch (IOException e) {
         System.out.println("IO Exception.");
      }
   }

}



PreviousNext

Related