Java Utililty Methods Path String Clean

List of utility methods to do Path String Clean

Description

The list of methods to do Path String Clean are organized into topic(s).

Method

StringcleanPath(String path, boolean trimStartSeparator)
clean Path
path = path.replaceAll("[/\\\\]+", "/");
if (trimStartSeparator) {
    path = path.replaceFirst("^/+", "");
return path;
StringcleanPath(String s)
clean Path
String retval = s.replace('\\', '_');
retval = retval.replace(':', '_');
retval = retval.replace('/', '_');
return retval;
StringcleanPath(String sText, boolean isWindows)
Clean path if not correct for the platform
if (sText == null || sText.equals(""))
    return "";
if (sText.startsWith("http://") || sText.startsWith("https://"))
    return sText;
String sFS = System.getProperty("file.separator");
if (isWindows) {
    sText = replace(sText, '/', sFS);
} else {
...
StringcleanPathSegment(final String toClean)
Removes characters that aren't acceptable in a file path (mostly for windows).
final String cleaned = toClean.replaceAll("[.\\\\/:*?\"<>|\\[\\]\\(\\)]", "");
if (cleaned.length() == 0)
    throw new IllegalStateException(
            "Path segment " + toClean + " has not valid characters and is thus empty");
return cleaned;
StringfilePathReplaceAll(String value)
file Path Replace All
String returnValue = value;
if (returnValue == null || returnValue.trim().equals("")) {
    return "";
returnValue = returnValue.replaceAll("/", "");
returnValue = returnValue.replaceAll("\\", "");
returnValue = returnValue.replaceAll("\\.\\.", ""); 
returnValue = returnValue.replaceAll("&", "");
...
StringfilePathTail(String filePath)
returns the component of the url after the last / OR \
String t = tail(filePath, "/");
t = tail(t, "\\");
return t;