private void validateFilePath(String filePath, String[] ext)
			throws IOException {

		try {
			//Creating a new file instance.
			File dir = new File(filePath);

			String targetImageFormat;

			boolean isSupportedImage = false;
			//Check if the specified file exists
			if (dir.exists()) {
				//Create an iterator for image reader.
				ImageInputStream iis = ImageIO.createImageInputStream(dir);
				Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);

				iis.flush();
				iis.close();
				
				//Check if the image has data to be read.
				//If not, then throw an error and terminate the
				//program.
				if (!readers.hasNext()) {
					System.out.println("Exception while reading target image."
							+ dir);
					System.exit(0);

				} 
				//Else, read the properties of the image
				else {
					ImageReader reader = readers.next();
					//Special Case:
					//Java Advanced Image Library reads TIFF image format
					//as "tif".
					//Therefore, if the a TIFF file is encountered
					//during the execution of the code then, set the
					//variable name as "tiff".
					if (reader.getFormatName().equals("tif")) {
						targetImageFormat = "tiff";
					} 
					//For any other format, use the string returned
					//by the Imagereader
					else {
						targetImageFormat = reader.getFormatName();
					}
					//Check if image format is one of the supported
					//legal format.
					for (int i = 0; i < ext.length; i++) {
						if (ext[i].equalsIgnoreCase(targetImageFormat)) {
							isSupportedImage = true;
							break;

						} else {
							isSupportedImage = false;
						}
					}
					//If the target image passes the validation
					//then set the required variables.
					if (isSupportedImage) {
						Main.setTARGET_IMG_DIR(filePath);
						Main.setTARGET_IMG_FORMAT(targetImageFormat
								.toLowerCase());
					} 
					//If the validation fails, then throw a message and
					//terminate the program.
					else {
						System.out.println("No file with " + ext[0] + " or "
								+ ext[1] + " or " + ext[2] + " or " + ext[3]
								+ " or " + ext[4] + " or " + ext[5]
								+ " was found in. " + dir);
						System.exit(0);
					}
				}
			} 
			//If the target image does not exists, then throw an appropriate
			//message and terminate the program.
			else {
				System.out.println("Target image does not exists in the path: "
						+ dir);
				System.exit(0);
			}
		} catch (Exception e) {
			System.out.println("Invalid Target Image path.");
			System.exit(0);
		}
	}