ملفات جافا
تعتبر معالجة الملفات جزءًا مهمًا من أي تطبيق.
لدى Java عدة طرق لإنشاء الملفات وقراءتها وتحديثها وحذفها.
معالجة ملفات جافا
يسمح لنا File
الفصل من java.io
الحزمة بالعمل مع الملفات.
لاستخدام File
الفئة ، أنشئ كائنًا للفئة وحدد اسم الملف أو اسم الدليل:
مثال
import java.io.File; // Import the File class
File myObj = new File("filename.txt"); // Specify the filename
إذا كنت لا تعرف ما هي الحزمة ، فاقرأ البرنامج التعليمي لحزم Java .
يحتوي 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 |
ستتعلم كيفية إنشاء الملفات وكتابتها وقراءتها وحذفها في الفصول التالية: