Pin It

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 : 

 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot