Friday, September 1, 2017

Creating Directory or folder using java program


If you want to create the directory or folder in your computer through the java program here i have give the example to create the folder and directory .

import java.io.*;
import java.nio.file.Files;
import java.nio.file.*;
class Mkdirectry {

    public static void main(String[] args) throws Exception {
          File file = new File("new folder");
        if (!file.exists()) {
            if (file.mkdir()) {
                System.out.println("Directory is created!");
            } else {
                System.out.println("Failed to create directory!");
            }
    }
}
}

using this code new folder created in the location where this Mkdirectry java program save.

If you want to create the folder on the specific location so follow this code


import java.io.*;
import java.nio.file.Files;
import java.nio.file.*;
class Mkdirectry {

    public static void main(String[] args) throws Exception {
      String path="/home/brij/new folder";//here you can give your location where you want to create the folder.
          File file = new File(path);
        if (!file.exists()) {
            if (file.mkdir()) {
                System.out.println("Directory is created!");
            } else {
                System.out.println("Failed to create directory!");
            }
    }
}
}

then execute this java program on cmd

javac Mkdirectry.java

java Mkdirectry

Now your folder is created..

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...