জাভা 7 থেকে File.02s ক্লাস চালু করা হয়েছে এতে (স্ট্যাটিক) পদ্ধতি রয়েছে যা ফাইল, ডিরেক্টরি বা অন্যান্য ধরনের ফাইলে কাজ করে।
createDirectory() ফাইলের পদ্ধতি ক্লাস প্রয়োজনীয় ডিরেক্টরির পথ গ্রহণ করে এবং একটি নতুন ডিরেক্টরি তৈরি করে।
উদাহরণ
জাভা উদাহরণ অনুসরণ করে ব্যবহারকারীর কাছ থেকে তৈরি করা ডিরেক্টরির পথ এবং নাম পড়ে এবং এটি তৈরি করে।
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
public class Test {
public static void main(String args[]) throws IOException {
System.out.println("Enter the path to create a directory: ");
Scanner sc = new Scanner(System.in);
String pathStr = sc.next()
System.out.println("Enter the name of the desired a directory: ");
pathStr = pathStr+sc.next();
//Creating a path object
Path path = Paths.get(pathStr);
//Creating a directory
Files.createDirectory(path);
System.out.println("Directory created successfully");
}
} আউটপুট
Enter the path to create a directory: D: Enter the name of the desired a directory: sample_directory Directory created successfully
আপনি যাচাই করলে, আপনি −
হিসাবে তৈরি করা ডিরেক্টরি দেখতে পারেন

createDirectories() পদ্ধতি প্রদত্ত ডিরেক্টরি তৈরি করে যার মধ্যে বিদ্যমান নেই প্যারেন্ট ডিরেক্টরি।
উদাহরণ
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
public class Test {
public static void main(String args[]) throws IOException {
System.out.println("Enter the path to create a directory: ");
Scanner sc = new Scanner(System.in);
String pathStr = sc.next();
System.out.println("Enter the name of the desired a directory: ");
pathStr = pathStr+sc.next();
//Creating a path object
Path path = Paths.get(pathStr);
//Creating a directory
Files.createDirectories(path);
System.out.println("Directories created successfully");
}
} আউটপুট
Enter the path to create a directory: D: Enter the name of the desired a directory: sample/test1/test2/test3/final_folder Directory created successfully
আপনি যাচাই করলে, আপনি −
হিসাবে তৈরি করা ডিরেক্টরি দেখতে পারেন
