java files

By | January 3, 2020

File class is present in java.io package and we can work with File class to read or write data.

Below are the methods present in File class.

Method Type Description
length() String Returns the length of the file.
canRead() Boolean Tests whether the file is readable or not.
canWrite() Boolean Tests whether the file is writable or not.
delete() Boolean Deletes a file or directory.
createNewFile() Boolean Creates a new empty file.
exists() Boolean Tests whether a file or directory exists or not.
compareTo(File filePath) int Compares two path names.
getParent() String It returns the pathname of the parent folder.
getName() Returns file name. Returns the name of the file
mkdir() Boolean Creates a directory

Delete file using java:

file.delete() method is used to delete a file or folder mentioned in the filepath. If the filepath denotes a directory, then the directory must be empty in order to be deleted.

 

Must reads:

How to read text file in Java

 

Note: If you like selenium99 tutorials and would like to contribute any articles, please send your articles to techygeeks99@gmail.com.

Leave a Reply

Your email address will not be published. Required fields are marked *