Here I input a string where user inputs filename with extension and i want to write a program that gives out the extension of the file but when I run this program it gives exception arrayindexoutofbound exception, any reason why?
import java.util.Scanner;
public class Extensionfile {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter file with data type");
String file = sc.next();
String parts[] = file.split(".");
String part1 = parts[1];
System.out.println("The file type is"+part1);
}
}