Friday, 6 September 2013

Why can't I use "." as a delimiter in split() function? [duplicate]

Why can't I use "." as a delimiter in split() function? [duplicate]

This question already has an answer here:
String.split returning null when using a dot 2 answers
I have to take an input file, and append a number at the end to its name
to use as output file. To achieve this, I use the following code:
String delimiter = ".";
String[] splitInput = inputLocation.split(delimiter);
String outputLocation = splitInput[0];
and I get the following exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0



I added the following statement to check the length of the splitInput
array, and I get 0 as output.
System.out.println(splitInput.length);
Later, I used ".x" as delimiter (my file being .xls). I can use ".x" and
achieve my purpose but I'm curious why won't "." work?

No comments:

Post a Comment