apache-comnons系列之commons-io-2.5 org.apache.commons.io.FileUtils学习笔记

来源:互联网 发布:淘宝网代理加盟 编辑:程序博客网 时间:2024/06/05 21:51

apache-comnons系列之commons-io-2.5 org.apache.commons.io.FileUtils学习笔记

概述

  • Facilities are provided in the following areas:
    • writing to a file
    • reading from a file
    • converting to and from a URL
    • comparing file content
    • file last changed date
    • calculating a checksum
    • make a directory including parent directories
    • copying files and directories
    • deleting files and directories
    • listing files and directories by filter and extension

测试

  • org.apache.commons.io.FileUtilsTestCase
  • directory
    • forceMkdir
      • Makes a directory, including any necessary but nonexistent parent directories.
    • copyFile
      • This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it
      • doCopyFile完成复制
    • deleteDirectory
      • Deletes a directory recursively
      • cleanDirectory/directory.delete
    • listFiles
      • Finds files within a given directory (and optionally its subdirectories). All files found are filtered by an IOFileFilter.
      • innerListFiles–FileFilterUtils.or–directory.listFiles((FileFilter) filter)
  • file
    • getFile/toFile
      • Construct a file from the set of name elements
    • openInputStream/openOutputStream
    • toURLs
      • Converts each of an array of File to a URL.
    • isFileNewer
      • Tests if the specified File is newer than the reference File.
    • byteCountToDisplaySize
      • Returns a human-readable version of the file size, where the input represents a specific number of bytes
    • contentEquals
      • This method checks to see if the two files are different lengths or if they point to the same file, before resorting to byte-by-byte comparison of the contents.
      • IOUtils.contentEquals(input1, input2)

FilenameUtils

  • This class defines six components within a filename
    • (example C:\dev\project\file.txt):
    • the prefix - C:\
    • the path - dev\project\
    • the full path - C:\dev\project\
    • the name - file.txt
    • the base name - file
    • the extension - txt
阅读全文
0 0
原创粉丝点击