Java Dosyaları
Dosya işleme, herhangi bir uygulamanın önemli bir parçasıdır.
Java, dosya oluşturmak, okumak, güncellemek ve silmek için çeşitli yöntemlere sahiptir.
Java Dosya İşleme
Paketteki File
sınıf, java.io
dosyalarla çalışmamızı sağlar.
Sınıfı kullanmak için File
sınıfın bir nesnesini oluşturun ve dosya adını veya dizin adını belirtin:
Örnek
import java.io.File; // Import the File class
File myObj = new File("filename.txt"); // Specify the filename
Paketin ne olduğunu bilmiyorsanız, Java Paketleri Eğitimimizi okuyun .
Sınıf File
, dosyalar hakkında bilgi oluşturmak ve almak için birçok faydalı yönteme sahiptir. Örneğin:
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 |
Sonraki bölümlerde dosyaların nasıl oluşturulacağını, yazılacağını, okunacağını ve silineceğini öğreneceksiniz: