How can I split to the last point of a line?
If you want to use split, you need to escape the dot (split expects a regular expression).
List<String> strings = Arrays.asList(myString.split("\\."));
If you only need to remove the last part, you can use a replaceAllregular expression:
myString = myString.replaceAll("\\.[^.]*$", "");
:
\\.[^.]*0$-
:
String myString = "20151221.1051.Test.01.properties";
List<String> strings = Arrays.asList(myString.substring(0,myString.lastIndexOf(".")).split("\\.(?=[^\\.])"));
for (String string : strings) {
System.out.println(string);
}
myString.substring(0,myString.lastIndexOf(".")) split("\\.(?=[^\\.])") :
20151221
1051
Test
01
, . , . : Apache Commons IO: https://commons.apache.org/proper/commons-io/apidocs/index.html?org/apache/commons/io/FileUtils.html
There is a getBaseName () method that helps you get the file name minus the full path and minus the extension. Another method, called getExtension (), will only result in a file extension. Slicing and dice are all you want!