जावा फ़ाइलें
फ़ाइल हैंडलिंग किसी भी एप्लिकेशन का एक महत्वपूर्ण हिस्सा है।
जावा में फाइलें बनाने, पढ़ने, अपडेट करने और हटाने की कई विधियाँ हैं।
जावा फ़ाइल हैंडलिंग
पैकेज File
से वर्ग , हमें फाइलों के साथ काम करने की अनुमति देता है।java.io
कक्षा का उपयोग करने के लिए, File
कक्षा का ऑब्जेक्ट बनाएं, और फ़ाइल नाम या निर्देशिका नाम निर्दिष्ट करें:
उदाहरण
import java.io.File; // Import the File class
File myObj = new File("filename.txt"); // Specify the filename
यदि आप नहीं जानते कि पैकेज क्या है, तो हमारा जावा पैकेज ट्यूटोरियल पढ़ें ।
फाइलों के बारे में जानकारी बनाने और प्राप्त करने के File
लिए कक्षा में कई उपयोगी तरीके हैं। उदाहरण के लिए:
Method | Type | Description |
---|---|---|
canRead() |
Boolean | Tests whether the file is readable or not |
canWrite() |
Boolean | Tests whether the file is writable or not |
createNewFile() |
Boolean | Creates an empty file |
delete() |
Boolean | Deletes a file |
exists() |
Boolean | Tests whether the file exists |
getName() |
String | Returns the name of the file |
getAbsolutePath() |
String | Returns the absolute pathname of the file |
length() |
Long | Returns the size of the file in bytes |
list() |
String[] | Returns an array of the files in the directory |
mkdir() |
Boolean | Creates a directory |
आप अगले अध्यायों में फाइलें बनाना, लिखना, पढ़ना और हटाना सीखेंगे: