##常用类库
[TOC]
###IO工具类org.apache.commons.io.IOUtils
####closeQuietly ( )
无条件的关闭Closeable
InputStream
OutputStream
Reader
Selector
ServerSocket
Socket
Writer
。
####toString ( )
将byte[]
InputStream
Reader
URI
URL
资源内容转为字符串
####copy ( )
copy(InputStream input, OutputStream output)
copy(InputStream input, Writer output, Charset inputEncoding)
copy(Reader input, OutputStream output, Charset outputEncoding) //会调用flush
copy(Reader input, Writer output)
copyLarge //大于2GB
####toByteArray ( )
将 InputStream
Reader
String
URI
URL
资源内容转为byte[]
####write ( )
void write(byte[] data, OutputStream output) //将data写入OutPutStream
void write(char[] data, Writer output)
void write(CharSequence data, Writer output)
writeChunked //using chunked writes.
//lineEnding默认null
void writeLines(Collection<?> lines, String lineEnding, OutputStream output, Charset encoding)
####toInputStream ( )
将 CharSequence
转为InputStream
####readLines ( )
static List<String> readLines(InputStream input, Charset encoding)
static List<String> readLines(Reader input)
####lineIterator ( )
static LineIterator lineIterator(InputStream input, Charset encoding)
static LineIterator lineIterator(Reader reader)
####readFully ( )
读取指定数量的字节,如果不够则返回失败
###文件操作工具类org.apache.commons.io.FileUtils
####deleteDirectory ( )
递归的删除一个目录
####readFileToString ( )
####deleteQuietly ( )
删除文件及子目录文件,不抛出异常,删除目标可以为空
####copyFile ( )
copyDirectoryToDirectory //复制文件夹到另一个文件夹下,保留文件日期
copyFile //复制文件,保留日期可选,或copy到OutoutStream
copyFileToDirectory //复制文件保留文件日期可选
copyInputStreamToFile
copyToFile //和copyInputStreamToFile一样
copyURLToFile //保存url资源到目标文件
####writeStringToFile ( )
####forceMkdir ( )
创建目录
####write ( )
write(File file, CharSequence data, Charset encoding) //文件不存在则创建
static void write(File file, CharSequence data, Charset encoding, boolean append)//是否追加写
static void writeByteArrayToFile(File file, byte[] data)
static void writeLines(File file, Collection<?> lines)
####listFiles ( )
static Collection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
//Finds files within a given directory (and optionally its subdirectories).
static Collection<File> listFiles(File directory, String[] extensions, boolean recursive)
//Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.
static Collection<File> listFilesAndDirs(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)
//Finds files within a given directory (and optionally its subdirectories).
####copyDirectory ( )
static void copyDirectory(File srcDir, File destDir)
//Copies a whole directory to a new location preserving the file dates.
static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate)
//Copies a whole directory to a new location.
static void copyDirectory(File srcDir, File destDir, FileFilter filter)
//Copies a filtered directory to a new location preserving the file dates.
static void copyDirectory(File srcDir, File destDir, FileFilter filter, boolean preserveFileDate)
//Copies a filtered directory to a new location.
static void copyDirectoryToDirectory(File srcDir, File destDir)
//Copies a directory to within another directory preserving the file dates.
####forceDelete ( )
static void forceDelete(File file)
//Deletes a file.
static void forceDeleteOnExit(File file)
//Schedules a file to be deleted when JVM exits.
###字符串工具类 org.apache.commons.lang3.StringUtils
isBlank ( ) isNotBlank ( ) isEmpty ( ) isNotEmpty ( ) join ( ) equals ( ) split ( ) EMPTY replace ( ) capitalize ( )
org.apache.http.util.EntityUtils
toString ( ) consume ( ) toByteArray ( ) consumeQuietly ( ) getContentCharSet ( )
org.apache.commons.io.FilenameUtils
getExtension ( ) getBaseName ( ) getName ( ) concat ( ) removeExtension ( ) normalize ( ) wildcardMatch ( ) separatorsToUnix ( ) getFullPath ( ) isExtension ( )
org.springframework.util.StringUtils
hasText ( ) hasLength ( ) isEmpty ( ) commaDelimitedListToStringArray ( ) collectionToDelimitedString ( ) replace ( ) delimitedListToStringArray ( ) uncapitalize ( ) collectionToCommaDelimitedString ( ) tokenizeToStringArray ( )
org.apache.commons.lang.ArrayUtils
contains ( ) addAll ( ) clone ( ) isEmpty ( ) add ( ) EMPTY_BYTE_ARRAY subarray ( ) indexOf ( ) isEquals ( ) toObject ( )
###org.apache.commons.lang.StringEscapeUtils
escapeHtml ( ) unescapeHtml ( ) escapeXml ( ) escapeSql ( ) unescapeJava ( ) escapeJava ( ) escapeJavaScript ( ) unescapeXml ( ) unescapeJavaScript ( )
###org.apache.http.client.utils.URLEncodedUtils
format ( ) parse ( )
org.apache.commons.codec.digest.DigestUtils
md5Hex ( ) shaHex ( ) sha256Hex ( ) sha1Hex ( ) sha ( ) md5 ( ) sha512Hex ( ) sha1 ( )
###org.apache.commons.collections.CollectionUtils
isEmpty ( ) isNotEmpty ( ) select ( ) transform ( ) filter ( ) find ( ) collect ( ) forAllDo ( ) addAll ( ) isEqualCollection ( )
###org.apache.commons.lang3.ArrayUtils
contains ( ) isEmpty ( ) isNotEmpty ( ) add ( ) clone ( ) addAll ( ) subarray ( ) indexOf ( ) EMPTY_OBJECT_ARRAY EMPTY_STRING_ARRAY
org.apache.commons.beanutils.PropertyUtils
getProperty ( ) setProperty ( ) getPropertyDescriptors ( ) isReadable ( ) copyProperties ( ) getPropertyDescriptor ( ) getSimpleProperty ( ) isWriteable ( ) setSimpleProperty ( ) getPropertyType ( )
###org.apache.commons.lang3.StringEscapeUtils
unescapeHtml4 ( ) escapeHtml4 ( ) escapeXml ( ) unescapeXml ( ) escapeJava ( ) escapeEcmaScript ( ) unescapeJava ( ) escapeJson ( ) escapeXml10 ( )
###org.apache.commons.beanutils.BeanUtils
copyProperties ( ) getProperty ( ) setProperty ( ) describe ( ) populate ( ) copyProperty ( ) cloneBean ( )
来源:oschina
链接:https://my.oschina.net/u/256606/blog/779747