'How to replace and split file path in java that makes the code platform independent

This is a follow up question for replace and split path

What are the changes needed to make it platform independent. so this solution will work for windows and linux machines. because the below code works very well in windows.

String IN= "\\\\in";
String SLASH= "\\\\";
String path = "C:\\Users\\Ashish.Gupta\\Documents\\in\\output\\in";
System.out.println("path: " + path);
String replacedPath = path.replaceAll(IN, SLASH);
System.out.println("replacedPath: " + replacedPath);
String[] batchIdPath = replacedPath.split("\\\\");
System.out.println("batchIdPath: " + java.util.Arrays.toString(batchIdPath));


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source