How to split String if it contains period symbol (.) in between?
I have to write a program which takes file name with any extension as a parameter and it should return the extension of that file.
If input parameters are as:
input_1 = testdata.properties
input_2 = userList.xlsx
Output would be:
output_1 = .properties
output_2 = .xlsx
Currently, I am using split() function with the regular expression (“.”), of String class to achieve this as mentioned below:
String fileExt = getExtenstion(“testdata.properties”);
System.out.println(“Extension of File : “+fileExt);
public String getExtension(String fileName)
String tempArray = fileName.split(“.”);
String fileExt = tempArray;
When I executed this program I got, “ArrayIndexOutOfBoundsException” for yellow highlighted line of code as mentioned above.
Please help me out to get this code corrected. Thanks in advance.
1026total visits,3visits today