Skip to content

Instantly share code, notes, and snippets.

@BalicantaYao
Created May 28, 2018 03:38
Show Gist options
  • Save BalicantaYao/bc81a049adc9b2902601863e4cf9cceb to your computer and use it in GitHub Desktop.
Save BalicantaYao/bc81a049adc9b2902601863e4cf9cceb to your computer and use it in GitHub Desktop.
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