Android examples for java.io:File Name
is File name Safe, no space or meta characters
import java.io.File; import java.util.regex.Pattern; public class Main{ /** Regular expression for safe filenames: no spaces or metacharacters */ private static final Pattern SAFE_FILENAME_PATTERN = Pattern .compile("[\\w%+,./=_-]+"); /**//from w w w . j a v a2 s . c o m * Check if a filename is "safe" (no metacharacters or spaces). * @param file The file to check */ public static boolean isFilenameSafe(File file) { // Note, we check whether it matches what's known to be safe, // rather than what's known to be unsafe. Non-ASCII, control // characters, etc. are all unsafe by default. return SAFE_FILENAME_PATTERN.matcher(file.getPath()).matches(); } }