Here you can find the source of sanitizeFilename(String name)
public static String sanitizeFilename(String name)
//package com.java2s; // under the terms of the GNU General Public License as published by the Free public class Main { /**/*from w w w.jav a 2 s . com*/ * Substitute any characters to be avoided in a file name with '_'. */ public static String sanitizeFilename(String name) { if (name.isEmpty()) throw new IllegalArgumentException("Empty file name!"); // replace all non-word characters (a word character is: [a-zA-Z_0-9]) except '.' and '-' return name.replaceAll("[\\W&&[^.-]]", "_"); } }