public class IOHelper extends Object
| 构造器和说明 |
|---|
IOHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
cleanDirectory(String strDirPath)
Cleans a directory without deleting it.
|
static boolean |
contentEquals(String strSourcePath,
String strDirPath)
Compares the contents of two files to determine if they are equal or not.
|
static void |
copyDirectory(String strSrcDirPath,
String strDestDirPath)
Copies a whole directory to a new location
|
static void |
copyDirectoryUnderDirectory(String strSrcDirPath,
String strDestDirPath)
Copies a whole directory to within another directory
|
static void |
copyFile(File src,
File dest)
Copies a file to a new location.
|
static void |
copyFile(String strSrcFilePath,
String strDestFilePath)
Copies a file to a new location.
|
static void |
copyFileToDirectory(String strSrcFilePath,
String strDestDirPath)
Copies a file to a directory
|
static void |
createNestDirectory(String strDir)
Makes a directory, including any necessary but nonexistent parent
directories.
|
static void |
creatFile(String filePath)
Creat file.
|
static void |
deleteDirectory(String strDirPath)
Deletes a directory recursively.
|
static void |
deleteFile(String strFilePath)
Deletes a file
|
static void |
downFileFromUrl(String url,
String strLocalFilePath)
Download URL file to local file
|
static void |
downSourceFromUrl(String strURL,
String strFilePath)
Copies bytes from the URL source to a file destination.
|
static String |
getBaseName(String strFileName)
Gets the base name, minus the full path and extension, from a full
filename.
|
static String |
getExtension(String strFileName)
Gets the extension of a filename.
|
static long |
getFreeSpace()
Returns the disk size of the volume which holds the working directory.
|
static long |
getFreeSpace(String strDrivePath)
Get the free space on a drive
|
static String |
getFullPath(String strFileName)
Gets the full path from a full filename, which is the prefix + path.
|
static String |
getFullPathNoEndSeparator(String strFileName)
Gets the full path from a full filename, which is the prefix + path, and
also excluding the final directory separator.
|
static String |
getName(String strFileName)
Gets the name minus the path from a full filename.
|
static String |
getPath(String strFileName)
Gets the path from a full filename, which excludes the prefix.
|
static String |
getPathNoEndSeparator(String strFileName)
Gets the path from a full filename, which excludes the prefix, and also
excluding the final directory separator.
|
static String |
getPrefix(String strFileName)
Gets the prefix from a full filename C:\dev\project\file.txt - C:\
|
static long |
getSizeOfDirectory(String strdirpath)
Counts the size of a directory recursively (sum of the length of all
files).
|
static long |
getSizeOfFile(String strfilepath)
Get the size of the specified file
|
static String |
getSourceFromUrl(String url)
Convert from a URL to a String
|
static String |
getTempDirectory()
Returns the path to the system temporary directory.
|
static String |
getUserDirectory()
Returns the path to the user's home directory.
|
static List<String> |
listFileNamesInDirectoryRecursive(String strdirpath,
String WildcardFileFilter)
Finds file names within a given directory (and its all subdirectories).
|
static List<String> |
listFilesInDirectory(String strdirpath)
Finds files within a given directory.
|
static List<String> |
listFilesInDirectory(String strdirpath,
String WildcardFileFilter)
Finds files within a given directory.
|
static List<String> |
listFilesInDirectory(String strdirpath,
String[] extensions)
Finds files within a given directory which match an array of extensions.
|
static List<String> |
listFilesInDirectoryRecursive(String strdirpath)
Finds files within a given directory (and its subdirectories).
|
static List<String> |
listFilesInDirectoryRecursive(String strdirpath,
String WildcardFileFilter)
Finds files within a given directory (and its all subdirectories).
|
static List<String> |
listFilesInDirectoryRecursive(String strdirpath,
String[] extensions)
Finds files within a given directory (and its subdirectories) which match
an array of extensions.
|
static List<String> |
listFilesInDirectoryRecursive(String strdirpath,
String WildcardFileFilter,
String WildcardDirFilter)
Finds files within a given directory (and its specified subdirectories).
|
static void |
main(String[] args)
The entry point of application.
|
static void |
moveDirectoryUnderDirectory(String strSrcDirPath,
String strDestDirPath)
Moves a directory to the destination directory.
|
static void |
moveFile(String strSrcFilePath,
String strDestFilePath)
Moves a file
|
static void |
moveFileToDirectory(String strSrcFilePath,
String strDestDirPath)
Moves a file to a directory.
|
static String |
readFileToString(String strFilePath)
Reads the contents of a file into a String
|
static List<String> |
readLinesToList(String strfilepath)
Reads the contents of a file line by line to a List of Strings
|
static boolean |
wildcardMatch(String filename,
String wildcardMatcher)
Checks a filename to see if it matches the specified wildcard matcher,
always testing case-sensitive.
|
static boolean |
wildcardMatch(String filename,
String wildcardMatcher,
org.apache.commons.io.IOCase caseSensitivity)
Checks a filename to see if it matches the specified wildcard matcher,
always testing case-sensitive.
|
static void |
writeLinesToFile(String strfilepath,
List<String> lines)
Writes a List of Strings to the specified File line by line.
|
static void |
writeStringToFile(String str,
String strFilePath)
Writes a String to a file creating the file if it does not exist.
|
public static void main(String[] args) throws Exception
args - the input argumentsException - the exceptionpublic static void cleanDirectory(String strDirPath)
strDirPath - the str dir pathpublic static boolean contentEquals(String strSourcePath, String strDirPath)
strSourcePath - the str source pathstrDirPath - the str dir pathpublic static void copyFile(String strSrcFilePath, String strDestFilePath)
strSrcFilePath - the str src file pathstrDestFilePath - the str dest file pathpublic static void copyFile(File src, File dest)
src - the srcdest - the destpublic static void copyFileToDirectory(String strSrcFilePath, String strDestDirPath)
strSrcFilePath - the str src file pathstrDestDirPath - the str dest dir pathpublic static void copyDirectory(String strSrcDirPath, String strDestDirPath)
strSrcDirPath - the str src dir pathstrDestDirPath - the str dest dir pathpublic static void copyDirectoryUnderDirectory(String strSrcDirPath, String strDestDirPath)
strSrcDirPath - the str src dir pathstrDestDirPath - the str dest dir pathpublic static String getSourceFromUrl(String url)
url - the urlpublic static void downSourceFromUrl(String strURL, String strFilePath)
strURL - the str urlstrFilePath - the str file pathpublic static void downFileFromUrl(String url, String strLocalFilePath)
url - the urlstrLocalFilePath - the str local file pathpublic static void deleteDirectory(String strDirPath)
strDirPath - the str dir pathpublic static void deleteFile(String strFilePath)
strFilePath - the str file pathpublic static String getTempDirectory()
public static String getUserDirectory()
public static void creatFile(String filePath)
filePath - the file pathpublic static void createNestDirectory(String strDir)
strDir - the str dirpublic static String getBaseName(String strFileName)
strFileName - the str file namepublic static String getExtension(String strFileName)
strFileName - the str file namepublic static String getFullPath(String strFileName)
strFileName - the str file namepublic static String getFullPathNoEndSeparator(String strFileName)
strFileName - the str file namepublic static String getName(String strFileName)
strFileName - the str file namepublic static String getPath(String strFileName)
strFileName - the str file namepublic static String getPathNoEndSeparator(String strFileName)
strFileName - the str file namepublic static String getPrefix(String strFileName)
strFileName - the str file namepublic static boolean wildcardMatch(String filename, String wildcardMatcher, org.apache.commons.io.IOCase caseSensitivity)
filename - - the filename to match onwildcardMatcher - - the wildcard string to match againstcaseSensitivity - - what case sensitivity rule to use, null means case-sensitivepublic static boolean wildcardMatch(String filename, String wildcardMatcher)
filename - - the filename to match onwildcardMatcher - - the wildcard string to match againstpublic static long getSizeOfFile(String strfilepath)
strfilepath - the strfilepathpublic static long getSizeOfDirectory(String strdirpath)
strdirpath - the strdirpathpublic static long getFreeSpace(String strDrivePath) throws IOException
strDrivePath - the str drive pathIOException - the io exceptionpublic static long getFreeSpace()
throws IOException
IOException - the io exceptionpublic static List<String> listFilesInDirectory(String strdirpath)
strdirpath - the strdirpathpublic static List<String> listFilesInDirectory(String strdirpath, String WildcardFileFilter)
strdirpath - the strdirpathWildcardFileFilter - filter to apply when finding files. such as "*.*"public static List<String> listFilesInDirectory(String strdirpath, String[] extensions)
strdirpath - the strdirpathextensions - an array of extensions.such as new String[]{"java","xml"}public static List<String> listFilesInDirectoryRecursive(String strdirpath)
strdirpath - the strdirpathpublic static List<String> listFilesInDirectoryRecursive(String strdirpath, String WildcardFileFilter)
strdirpath - the strdirpathWildcardFileFilter - filter to apply when finding files. such as "*.*"public static List<String> listFileNamesInDirectoryRecursive(String strdirpath, String WildcardFileFilter)
strdirpath - the strdirpathWildcardFileFilter - filter to apply when finding files. such as "*.*"public static List<String> listFilesInDirectoryRecursive(String strdirpath, String[] extensions)
strdirpath - the strdirpathextensions - an array of extensions.such as new String[]{"java","xml"}public static List<String> listFilesInDirectoryRecursive(String strdirpath, String WildcardFileFilter, String WildcardDirFilter)
strdirpath - the strdirpathWildcardFileFilter - filter to apply when finding files. such as "*.*"WildcardDirFilter - filter to apply when finding directory. such as "*"public static void moveFile(String strSrcFilePath, String strDestFilePath)
strSrcFilePath - the str src file pathstrDestFilePath - the str dest file pathpublic static void moveFileToDirectory(String strSrcFilePath, String strDestDirPath)
strSrcFilePath - the str src file pathstrDestDirPath - the str dest dir pathpublic static void moveDirectoryUnderDirectory(String strSrcDirPath, String strDestDirPath)
strSrcDirPath - the str src dir pathstrDestDirPath - the str dest dir pathpublic static List<String> readLinesToList(String strfilepath)
strfilepath - the strfilepathpublic static String readFileToString(String strFilePath)
strFilePath - the str file pathpublic static void writeLinesToFile(String strfilepath, List<String> lines)
strfilepath - the strfilepathlines - the linesCopyright © 2017. All rights reserved.