📄 filevalidator.java
字号:
package firewall.common;/** * Title: Professional Java Servlet Programming - Chapter 2 * Description: Class to provide common static utility methods * Copyright: Copyright (c) 2001 * Company: * @author Andrew Harbourne-Thomas * @version 1.0 */public class FileValidator{ /** * Provides a (limited) String array of valid * character file extensions */ public static final String[] VALID_EXTENSIONS = {"txt", "html", "htm", "java"}; /** * This method is desinged to determine if the filename passed * is valid according to the following rules: * filename cannot be null or empty, * filename must end in a valid extension (as specified) * * @param filename - the filename to be checked * @return boolean indication if the filename is valid; * true if it is, false otherwise. */ public static boolean isFileNameValid(String filename) { if (filename == null || filename.length() == 0) { return false; } for (int i = 0; i < VALID_EXTENSIONS.length; i++) { if (filename.endsWith("." + VALID_EXTENSIONS[i])) { return true; } } return false; } /** * This method recieves a file list (String[]) and checks that all * files are valid names. If not, it removes them (replaces with null). */ public static void cleanFileList(String[] files) { for (int i = 0; i < files.length; i++) { if (!isFileNameValid(files[i])) { files[i] = null; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -