Posts

Showing posts with the label file handling in Java

Creation of Files in Java जावा में फाइल निर्माण

File creation is an essential part of file handling in Java. We use the `File` class from the java.io package to create new files. जावा में फाइल हैंडलिंग का एक महत्वपूर्ण हिस्सा फाइल निर्माण है। हम नई फाइल बनाने के लिए java.io पैकेज की `File` क्लास का उपयोग करते हैं। Key Points / मुख्य बिंदु:- 1. Use File class to create new files.    नई फाइल बनाने के लिए File क्लास का उपयोग करें। 2. `createNewFile()` method returns true if the file is created successfully.    `createNewFile()` मेथड true लौटाता है यदि फाइल सफलतापूर्वक बनती है। 3. If the file already exists, the method returns false.    यदि फाइल पहले से मौजूद है, तो मेथड false लौटाता है। 💻 Example 1: Create a File import java.io.File; import java.io.IOException; public class CreateFileExample {     public static void main(String[] args) {         try {             File file = new File("myfile.txt");             if (fil...

Java File Class जावा फाइल क्लास

The File class in Java is part of the java.io package and is used to represent the path of files and directories. The File class does not read or write data directly; it only provides information about files and directories and methods to create, delete, or check properties. जावा में File क्लास java.io पैकेज का हिस्सा है और इसका प्रयोग फाइल एवं डायरेक्टरी के पाथ को प्रदर्शित करने के लिए किया जाता है। File क्लास डेटा को सीधे पढ़ती या लिखती नहीं है; यह केवल फाइल और डायरेक्टरी की जानकारी और उन्हें बनाने, हटाने या चेक करने की सुविधा देती है। 🔹 Constructors of File Class (कन्स्ट्रक्टर्स) File(String pathname) – Creates a new File instance using a given pathname. File(String pathname) – दिये गये पाथनेम के आधार पर नई File ऑब्जेक्ट बनाता है। File(String parent, String child) – Creates a File object from directory and filename separately. File(String parent, String child) – डायरेक्टरी और फाइल का नाम अलग-अलग देकर File ऑब्जेक्ट बनाता है। 🔹 Common Methods of Fil...