. Write a Java program that reads a file and throws an exception if the file is empty.

Source Code:

import java.io.File;

public class EmptyFileCheck {
public static void main(String[] args) {
try {
File f = new File(“test.txt”);
if(f.length() == 0) {
throw new Exception(“File is empty”);
}
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}

Output: