Java - removing invalid characters from a file name

public static String replaceUnsupportedFileNameChars(String fileName, String replacement)
{
    return fileName.replaceAll("[\\\\/:*?\"<>|]", replacement!=null?replacement:"_");
}

 

Category: Java Tutorials