How to split a path platform independent?
- by Janusz
I'm using the following code to get an array with all sub directories from a given path.
String[] subDirs = path.split(File.separator);
I need the array to check if certain folders are at the right place in this path.
This looked like a good solution until findBugs complains that File.separator is used as a regular expression. It seems that passing the windows file separator to a function that is building a regex from it is a bad idea because the backslash being an escape character.
How can I split the path in a cross platform way without using File.separator?
Or is code like this okay?
String[] subDirs = path.split("/");