How do I get my screen size?

package org.kodejava.awt;

import java.awt.*;

public class ScreenSizeExample {
    public static void main(String[] args) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        System.out.println("Screen Width: " + screenSize.getWidth());
        System.out.println("Screen Height: " + screenSize.getHeight());
    }
}

The output of the code snippet above:

Screen Width: 2560.0
Screen Height: 1080.0

How do I determine if a pathname is a directory?

To determine if an abstract pathname is a directory we can use the File.isDirectory() method. Here is an example code.

package org.kodejava.io;

import java.io.File;

public class IsDirectoryExample {
    public static void main(String[] args) {
        // Creates a instance of File.
        File file = new File("C:/Users/wsaryada");

        // Check if the abstract pathname is a directory by calling
        // isDirectory() method of the File class.
        if (file.isDirectory()) {
            System.out.println("This file is a directory.");
        } else {
            System.out.println("This is just an ordinary file.");
        }
    }
}

How do I get total space and free space of my disk?

package org.kodejava.io;

import java.io.File;

public class FreeSpaceExample {
    public static void main(String[] args) {
        // We create an instance of a File to represent a partition
        // of our file system. For instance here we used a drive D:
        // as in Windows operating system. 
        File file = new File("D:");

        // Using the getTotalSpace() we can get an information of
        // the actual size of the partition, and we convert it to
        // mega bytes. 
        long totalSpace = file.getTotalSpace() / (1024 * 1024);

        // Next we get the free disk space as the name of the
        // method shown us, and also get the size in mega bytes.
        long freeSpace = file.getFreeSpace() / (1024 * 1024);

        // Just print out the values.
        System.out.println("Total Space = " + totalSpace + " Mega Bytes");
        System.out.println("Free Space = " + freeSpace + " Mega Bytes");
    }
}

Here is the result of the program:

Total Space = 1907605 Mega Bytes
Free Space = 946213 Mega Bytes

How do I rename a file or directory?

package org.kodejava.io;

import java.io.File;
import java.io.IOException;

public class FileRenameExample {
    public static void main(String[] args) throws IOException {
        // Creates a new file called OldHouses.csv
        File oldFile = new File("OldHouses.csv");
        boolean created = oldFile.createNewFile();
        System.out.println("File created? " + created);

        // Creates the target file.
        File newFile = new File("NewHouses.csv");

        // The renameTo() method renames file or directory to a
        // new name by passing the new destination file.
        boolean renamed = oldFile.renameTo(newFile);
        System.out.println("File renamed? " + renamed);
    }
}

How do I check if a file is hidden?

The File.isHidded() method checks to see if the file represented by aFile object is a hidden file. The definition of hidden is varied between operating systems. On UNIX based systems, a file is considered to be hidden when their name begins with a period character ('.'). On Windows operating system, a file is considered to be hidden if it has been marked hidden in the filesystem.

This File.isHidden() method returns true if and only if the file denoted by this File object is hidden according to the conventions of the underlying platform.

package org.kodejava.io;

import java.io.File;
import java.io.IOException;

public class FileHiddenExample {
    public static void main(String[] args) throws IOException {
        File file = new File("Hidden.txt");
        file.createNewFile();

        // We are using the isHidden() method to check whether a file
        // is hidden.
        if (file.isHidden()) {
            System.out.println("File is hidden!");
        } else {
            System.out.println("File is not hidden!");
        }
    }
}

If you want to set the file attribute to hidden in Windows operating system you can see it in the following example: How do I set the value of file attributes?