Menu
Coddy logo textTech

Information

Lesson 3 of 11 in Coddy's File Handling in Java course.

In the previous lesson, we saw how to create a File object from any file. Now let's see some basic operations:

File dataFile = new File("data.txt");
System.out.println("File name: " + dataFile.getName());
System.out.println("Absolute path: " + dataFile.getAbsolutePath());
System.out.println("File size in bytes " + dataFile.length());

The above code prints the name, absolute path, and size of data.txt file.

challenge icon

Challenge

Easy

We have created a file named "coddy.txt" in the file system.

Your task is to create an object of this file and print the name, path, and size of this file, separated by a new line.

Try it yourself

import java.io.File;

class Main {
    public static void main(String[] args) {
        // Write code here
    }
}

All lessons in File Handling in Java