The getImageInfo() method takes a file path as input and creates a File object. It then uses the length() method to get the file size and the ImageIO.read() method to read the file and get its format name, which represents the file type. The method then prints the file size and type. In the main() method, we call getImageInfo() with the file path.
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main {
public static void getImageInfo(String file) throws IOException {
File imageFile = new File(file);
long fileSize = imageFile.length();
String fileType = ImageIO.read(imageFile).getFormatName();
System.out.println("File size: " + fileSize + " bytes");
System.out.println("File type: " + fileType);
}
public static void main(String[] args) throws IOException {
getImageInfo("image.jpg");
}
}