Module org.htmlunit

Class FileUtils

java.lang.Object
org.htmlunit.util.FileUtils

public final class FileUtils extends Object
File utility class for functions not covered by third-party libraries.
Author:
Ronald Brill
  • Method Details

    • sanitizeFilename

      public static String sanitizeFilename(String name)
      Makes the given name usable as the name of a file, the way the browsers do it for downloaded files.
      • Characters that are not allowed in file names on at least one platform (\ / : * ? " < > |), the control characters (U+0000 - U+001F) and DEL (U+007F) are replaced by an underscore. Because the path separators are replaced, the result is always a plain file name; e.g. ../../evil.txt becomes _.._evil.txt, so the name can be resolved against a folder without leaving it.
      • Leading dots and white space (no hidden files) and trailing dots and white space are removed.

      The name is not checked any further; e.g. names reserved by Windows (like CON or NUL) and the maximum length of a file name are not taken into account.

      Parameters:
      name - the name to sanitize, can be null
      Returns:
      the sanitized name or null if the name is null or nothing is left