Skip to content

9.1 File Handling Basics

🎯 Lesson Objectives

  • java.io.File क्लास का उपयोग।
  • फ़ाइल का अस्तित्व (exists()), साइज़ (length()), और अनुमतियाँ जाँचना।
  • createNewFile() और delete() का उपयोग।
import java.io.File;
import java.io.IOException;

public class FileBasicsDemo {
    public static void main(String[] args) {
        File file = new File("notes.txt");

        try {
            if (file.createNewFile()) {
                System.out.println("नई फ़ाइल बनाई गई: " + file.getName());
            } else {
                System.out.println("फ़ाइल पहले से मौजूद है।");
            }

            System.out.println("पूर्ण पाथ: " + file.getAbsolutePath());
            System.out.println("क्या फ़ाइल पढ़ी जा सकती है? " + file.canRead());
            System.out.println("फ़ाइल साइज़: " + file.length() + " बाइट्स");
        } catch (IOException e) {
            System.out.println("एरर: " + e.getMessage());
        }
    }
}

🧭 Navigation

Last updated on