Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe for all free courses

Java 7 new feature : Creating files and directories

Program to demonstrate Java 7 new feature : Creating files and directories.

package com.hubberspot.nio;

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

public class FileCreation {

    public static void main(String[] args) {

        Path pathToDirectory = FileSystems.getDefault().getPath("C:/Ablage/dev/workspace");
        
        try {
            
            Files.createDirectories(pathToDirectory);
            System.out.println("Directory created at path : " + pathToDirectory);
        
        } catch (IOException e) {
            
            e.printStackTrace();
        }

        Path pathToFile = FileSystems.getDefault().getPath("C:/Ablage/dev/workspace/hello.pdf");
        
        try {
            
            Files.createFile(pathToFile);
            System.out.println("File created at path : " + pathToFile);
            
        } catch (IOException e) {
        
            e.printStackTrace();
        }
        
    }

}



Output of the program : 

 
 
© 2021 Learn Java by Examples Template by Hubberspot