नोट्स को एक फ़ोल्डर में संगठित करना
चीज़ों को व्यवस्थित रखने के लिए, आपकी ऐप को नोट्स एक समर्पित फ़ोल्डर में सेव करने चाहिए. इस अभ्यास में, आप "notes" नाम की एक डायरेक्टरी बनाएँगे और उसका पाथ प्रिंट करेंगे. इससे संबंधित फ़ाइलें एक साथ रहती हैं और ढूँढ़ना आसान होता है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Java में इनपुट/आउटपुट और स्ट्रीम्स
अभ्यास निर्देश
notesकी ओर इशारा करने वालाFileऑब्जेक्टnotesDirबनाएँ.- सिस्टम में
notesनाम की डायरेक्टरी बनाएँ. notesनाम की डायरेक्टरी का relative path प्राप्त करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
class DirectoryManager {
public static void main(String[] args) {
try {
// Create a File object to represent the directory
File notesDir = ____ _____("notes");
// Create a directory in the system
if (____.____()) {
System.out.println("Directory 'notes' created successfully");
}
// Retrieve and print the relative path of the directory
System.out.println("Relative Path: " + ____.____());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}