Force a valid Windows filenameTag(s): IO
public class FileUtils { /** * replace illegal characters in a filename with "_" * illegal characters : * : \ / * ? | < > * @param name * @return */ public static String sanitizeFilename(String name) { return name.replaceAll("[:\\\\/*?|<>]", "_"); } public static void main(String args[]) throws Exception { String test = "invalid : file ? name.txt"; System.out.println(test + " -> " + FileUtils.sanitizeFilename(test)); /* output : * * invalid : file ? name. -> invalid _ file _ name.txt * */ } }
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com