ImageTest

// ImageTest – try/catch, throw
public class ImageTest {

	// method
	static void print(String filename) {
		// read image & find image info
		BufferedImage image = null;
		try {			
			image = ImageIO.read(new File(filename));
			int width = image.getWidth();
			int height = image.getHeight();
			String ext = filename.substring(filename.lastIndexOf('.') + 1);
			System.out.println("filename=" + filename);
			System.out.println("width=" + width);
			System.out.println("height=" + height);
			System.out.println("format=" + ext);
		} catch (IOException e) {
			System.out.println(filename + " not found");
			e.printStackTrace();
		}
	}

	// method
	static void print2(String filename) throws IOException {
		// read image & find image info
		BufferedImage image = null;
		image = ImageIO.read(new File(filename));
		int width = image.getWidth();
		int height = image.getHeight();
		String ext = filename.substring(filename.lastIndexOf('.') + 1);
		System.out.println("filename=" + filename);
		System.out.println("width=" + width);
		System.out.println("height=" + height);
		System.out.println("format=" + ext);
	}
	
	public static void main(String[] args) {
		String filename = "dog1.jpg";
		
		// command line arguments
		if (args.length >= 1) {
			filename = args[0];
			System.out.println("args0=" + filename);
		} 

		print(filename);
		
		try {
			print2(filename);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}