Java File Class

Java File Class

A stream in Java is a carrier of data. Nearly 30 stream classes exist in package. Also there are three non-stream classes in package – File, InputStreamReader and OutputStreamWriter. Last two are used as bridges or converters or adapters between low-level byte streams (supported by OS like in, out and err) and character streams.

File class is used to retrieve metadata of a file like the size and permissions for read and write etc.

Following is the class signature of Java File class as defined in package.

public class File extends Object implements Serializable, Comparable

Example on Java File Class – Retrieving meta data of a file.

Output screenshot of Java File Class

All methods are self-explanatory. getAbsolutePath() returns the class path of abc.txt file. lastModified() returns the file creation date or latest modified date. length() returns the size of the file in bytes.

Read more on File class – Changing File Properties

Leave a Reply

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