Created
May 28, 2018 03:38
-
-
Save BalicantaYao/bc81a049adc9b2902601863e4cf9cceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileNameUtils { | |
private static final String[] ILLEGAL_CHARACTERS = | |
{ "/", "\n", "\r", "\t", "\0", "\f", "`", "?", "*", "\\", "<", ">", "|", "\"", ":" }; | |
private static final String DEFAULT_SEPARATOR = "_"; | |
public static String normalizeFileName(String fileName, String separator){ | |
for (String illegalCharacter : ILLEGAL_CHARACTERS) { | |
fileName = fileName.replace(illegalCharacter, separator); | |
} | |
return fileName; | |
} | |
public static String normalizeFileName(String fileName){ | |
return normalizeFileName(fileName, DEFAULT_SEPARATOR); | |
} | |
public static void main (String args[]){ | |
System.out.println(normalizeFileName("t?test:testk<.jpg", "*")); | |
System.out.println(normalizeFileName("t?test:testk<.jpg")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment