Java Path String Clean cleanPathSegment(final String toClean)

Here you can find the source of cleanPathSegment(final String toClean)

Description

Removes characters that aren't acceptable in a file path (mostly for windows).

License

Apache License

Declaration

public static String cleanPathSegment(final String toClean) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from ww w  .  j av  a2s.  com
     * Removes characters that aren't acceptable in a file path (mostly for windows).
     */
    public static String cleanPathSegment(final String toClean) {
        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;
    }
}

Related

  1. cleanPath(String path)
  2. cleanPath(String path)
  3. cleanPath(String path, boolean trimStartSeparator)
  4. cleanPath(String s)
  5. cleanPath(String sText, boolean isWindows)
  6. filePathReplaceAll(String value)
  7. filePathTail(String filePath)