Java File Name Sanitize sanitizeToValidFilename(String name)

Here you can find the source of sanitizeToValidFilename(String name)

Description

sanitize To Valid Filename

License

Open Source License

Declaration

public static String sanitizeToValidFilename(String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String sanitizeToValidFilename(String name) {
        String[] invalidSymbols = new String[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" };
        String sanitizedName = name;

        for (String currentSymbol : invalidSymbols) {
            sanitizedName = sanitizedName.replaceAll("[\\" + currentSymbol + "]", "_");
        }/*  ww w. j a  v  a 2s. co m*/
        return sanitizedName;
    }
}

Related

  1. sanitizeFileName(String name)
  2. sanitizeFileName(String s)
  3. sanitizeFilename(String toClean)
  4. sanitizeFilenameForWindows(String filename)
  5. sanitizeForFileName(final String orig)