-
public final class FileUtilsAuthor: bin.yang Maintainer: bin.yang Date: 2019/6/29 0029 Copyright: 2019 Inc. All rights reserved. Desc: 文件操作
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceFileUtils.OnReplaceListener
-
Method Summary
Modifier and Type Method Description static booleanisSDCardEnable()Return whether sdcard is enabled by environment. static FilegetFileByPath(String filePath)Return the file by path. static booleanisFileExists(String filePath)Return whether the file exists. static booleanisFileExists(File file)Return whether the file exists. static booleanrename(String filePath, String newName)Rename the file. static booleanrename(File file, String newName)Rename the file. static booleanisDir(String dirPath)Return whether it is a directory. static booleanisDir(File file)Return whether it is a directory. static booleanisFile(String filePath)Return whether it is a file. static booleanisFile(File file)Return whether it is a file. static booleancreateOrExistsDir(String dirPath, Context context)Create a directory if it doesn't exist, otherwise do nothing. static booleancreateOrExistsDir(File file)Create a directory if it doesn't exist, otherwise do nothing. static booleancreateOrExistsFile(String filePath, Context context)Create a file if it doesn't exist, otherwise do nothing. static booleancreateOrExistsFile(File file)Create a file if it doesn't exist, otherwise do nothing. static booleancreateFileByDeleteOldFile(String filePath)Create a file if it doesn't exist, otherwise delete old file before creating. static booleancreateFileByDeleteOldFile(File file)Create a file if it doesn't exist, otherwise delete old file before creating. static booleancopyDir(String srcDirPath, String destDirPath)Copy the directory. static booleancopyDir(String srcDirPath, String destDirPath, FileUtils.OnReplaceListener listener)Copy the directory. static booleancopyDir(File srcDir, File destDir)Copy the directory. static booleancopyDir(File srcDir, File destDir, FileUtils.OnReplaceListener listener)Copy the directory. static booleancopyFile(String srcFilePath, String destFilePath)Copy the file. static booleancopyFile(String srcFilePath, String destFilePath, FileUtils.OnReplaceListener listener)Copy the file. static booleancopyFile(File srcFile, File destFile)Copy the file. static booleancopyFile(File srcFile, File destFile, FileUtils.OnReplaceListener listener)Copy the file. static booleanmoveDir(String srcDirPath, String destDirPath)Move the directory. static booleanmoveDir(String srcDirPath, String destDirPath, FileUtils.OnReplaceListener listener)Move the directory. static booleanmoveDir(File srcDir, File destDir)Move the directory. static booleanmoveDir(File srcDir, File destDir, FileUtils.OnReplaceListener listener)Move the directory. static booleanmoveFile(String srcFilePath, String destFilePath)Move the file. static booleanmoveFile(String srcFilePath, String destFilePath, FileUtils.OnReplaceListener listener)Move the file. static booleanmoveFile(File srcFile, File destFile)Move the file. static booleanmoveFile(File srcFile, File destFile, FileUtils.OnReplaceListener listener)Move the file. static booleandelete(String filePath)Delete the directory. static booleandelete(File file)Delete the directory. static booleandeleteDir(String dirPath)Delete the directory. static booleandeleteDir(File dir)Delete the directory. static booleandeleteFile(String srcFilePath)Delete the file. static booleandeleteFile(File file)Delete the file. static booleandeleteAllInDir(String dirPath)Delete the all in directory. static booleandeleteAllInDir(File dir)Delete the all in directory. static booleandeleteFilesInDir(String dirPath)Delete all files in directory. static booleandeleteFilesInDir(File dir)Delete all files in directory. static booleandeleteFilesInDirWithFilter(String dirPath, FileFilter filter)Delete all files that satisfy the filter in directory. static booleandeleteFilesInDirWithFilter(File dir, FileFilter filter)Delete all files that satisfy the filter in directory. static List<File>listFilesInDir(String dirPath)Return the files in directory. static List<File>listFilesInDir(File dir)Return the files in directory. static List<File>listFilesInDir(String dirPath, boolean isRecursive)Return the files in directory. static List<File>listFilesInDir(File dir, boolean isRecursive)Return the files in directory. static List<File>listFilesInDirWithFilter(String dirPath, FileFilter filter)Return the files that satisfy the filter in directory. static List<File>listFilesInDirWithFilter(File dir, FileFilter filter)Return the files that satisfy the filter in directory. static List<File>listFilesInDirWithFilter(String dirPath, FileFilter filter, boolean isRecursive)Return the files that satisfy the filter in directory. static List<File>listFilesInDirWithFilter(File dir, FileFilter filter, boolean isRecursive)Return the files that satisfy the filter in directory. static longgetFileLastModified(String filePath)Return the time that the file was last modified. static longgetFileLastModified(File file)Return the time that the file was last modified. static StringgetFileCharsetSimple(String filePath)Return the charset of file simply. static StringgetFileCharsetSimple(File file)Return the charset of file simply. static intgetFileLines(String filePath)Return the number of lines of file. static intgetFileLines(File file)Return the number of lines of file. static StringgetDirSize(String dirPath)Return the size of directory. static StringgetDirSize(File dir)Return the size of directory. static StringgetFileSize(String filePath)Return the length of file. static StringgetFileSize(File file)Return the length of file. static longgetDirLength(String dirPath)Return the length of directory. static longgetDirLength(File dir)Return the length of directory. static longgetFileLength(String filePath)Return the length of file. static longgetFileLength(File file)Return the length of file. static StringgetFileMD5ToString(String filePath)Return the MD5 of file. static StringgetFileMD5ToString(File file)Return the MD5 of file. static Array<byte>getFileMD5(String filePath)Return the MD5 of file. static Array<byte>getFileMD5(File file)Return the MD5 of file. static StringgetDirName(File file)Return the file's path of directory. static StringgetDirName(String filePath)Return the file's path of directory. static StringgetFileName(File file)Return the name of file. static StringgetFileName(String filePath)Return the name of file. static StringgetFileNameNoExtension(File file)Return the name of file without extension. static StringgetFileNameNoExtension(String filePath)Return the name of file without extension. static StringgetFileExtension(File file)Return the extension of file. static StringgetFileExtension(String filePath)Return the extension of file. -
-
Method Detail
-
isSDCardEnable
static boolean isSDCardEnable()
Return whether sdcard is enabled by environment.
-
getFileByPath
static File getFileByPath(String filePath)
Return the file by path.
- Parameters:
filePath- The path of file.
-
isFileExists
static boolean isFileExists(String filePath)
Return whether the file exists.
- Parameters:
filePath- The path of file.
-
isFileExists
static boolean isFileExists(File file)
Return whether the file exists.
- Parameters:
file- The file.
-
rename
static boolean rename(String filePath, String newName)
Rename the file.
- Parameters:
filePath- The path of file.newName- The new name of file.
-
rename
static boolean rename(File file, String newName)
Rename the file.
- Parameters:
file- The file.newName- The new name of file.
-
isDir
static boolean isDir(String dirPath)
Return whether it is a directory.
- Parameters:
dirPath- The path of directory.
-
isDir
static boolean isDir(File file)
Return whether it is a directory.
- Parameters:
file- The file.
-
isFile
static boolean isFile(String filePath)
Return whether it is a file.
- Parameters:
filePath- The path of file.
-
createOrExistsDir
static boolean createOrExistsDir(String dirPath, Context context)
Create a directory if it doesn't exist, otherwise do nothing.如果sd不存在则创建在Cache目录
- Parameters:
dirPath- The path of directory.
-
createOrExistsDir
static boolean createOrExistsDir(File file)
Create a directory if it doesn't exist, otherwise do nothing.
- Parameters:
file- The file.
-
createOrExistsFile
static boolean createOrExistsFile(String filePath, Context context)
Create a file if it doesn't exist, otherwise do nothing.如果sd不存在则创建在Cache目录
- Parameters:
filePath- The path of file.
-
createOrExistsFile
static boolean createOrExistsFile(File file)
Create a file if it doesn't exist, otherwise do nothing.
- Parameters:
file- The file.
-
createFileByDeleteOldFile
static boolean createFileByDeleteOldFile(String filePath)
Create a file if it doesn't exist, otherwise delete old file before creating.
- Parameters:
filePath- The path of file.
-
createFileByDeleteOldFile
static boolean createFileByDeleteOldFile(File file)
Create a file if it doesn't exist, otherwise delete old file before creating.
- Parameters:
file- The file.
-
copyDir
static boolean copyDir(String srcDirPath, String destDirPath)
Copy the directory.
- Parameters:
srcDirPath- The path of source directory.destDirPath- The path of destination directory.
-
copyDir
static boolean copyDir(String srcDirPath, String destDirPath, FileUtils.OnReplaceListener listener)
Copy the directory.
- Parameters:
srcDirPath- The path of source directory.destDirPath- The path of destination directory.listener- The replace listener.
-
copyDir
static boolean copyDir(File srcDir, File destDir)
Copy the directory.
- Parameters:
srcDir- The source directory.destDir- The destination directory.
-
copyDir
static boolean copyDir(File srcDir, File destDir, FileUtils.OnReplaceListener listener)
Copy the directory.
- Parameters:
srcDir- The source directory.destDir- The destination directory.listener- The replace listener.
-
copyFile
static boolean copyFile(String srcFilePath, String destFilePath)
Copy the file.
- Parameters:
srcFilePath- The path of source file.destFilePath- The path of destination file.
-
copyFile
static boolean copyFile(String srcFilePath, String destFilePath, FileUtils.OnReplaceListener listener)
Copy the file.
- Parameters:
srcFilePath- The path of source file.destFilePath- The path of destination file.listener- The replace listener.
-
copyFile
static boolean copyFile(File srcFile, File destFile)
Copy the file.
- Parameters:
srcFile- The source file.destFile- The destination file.
-
copyFile
static boolean copyFile(File srcFile, File destFile, FileUtils.OnReplaceListener listener)
Copy the file.
- Parameters:
srcFile- The source file.destFile- The destination file.listener- The replace listener.
-
moveDir
static boolean moveDir(String srcDirPath, String destDirPath)
Move the directory.
- Parameters:
srcDirPath- The path of source directory.destDirPath- The path of destination directory.
-
moveDir
static boolean moveDir(String srcDirPath, String destDirPath, FileUtils.OnReplaceListener listener)
Move the directory.
- Parameters:
srcDirPath- The path of source directory.destDirPath- The path of destination directory.listener- The replace listener.
-
moveDir
static boolean moveDir(File srcDir, File destDir)
Move the directory.
- Parameters:
srcDir- The source directory.destDir- The destination directory.
-
moveDir
static boolean moveDir(File srcDir, File destDir, FileUtils.OnReplaceListener listener)
Move the directory.
- Parameters:
srcDir- The source directory.destDir- The destination directory.listener- The replace listener.
-
moveFile
static boolean moveFile(String srcFilePath, String destFilePath)
Move the file.
- Parameters:
srcFilePath- The path of source file.destFilePath- The path of destination file.
-
moveFile
static boolean moveFile(String srcFilePath, String destFilePath, FileUtils.OnReplaceListener listener)
Move the file.
- Parameters:
srcFilePath- The path of source file.destFilePath- The path of destination file.listener- The replace listener.
-
moveFile
static boolean moveFile(File srcFile, File destFile)
Move the file.
- Parameters:
srcFile- The source file.destFile- The destination file.
-
moveFile
static boolean moveFile(File srcFile, File destFile, FileUtils.OnReplaceListener listener)
Move the file.
- Parameters:
srcFile- The source file.destFile- The destination file.listener- The replace listener.
-
delete
static boolean delete(String filePath)
Delete the directory.
- Parameters:
filePath- The path of file.
-
deleteDir
static boolean deleteDir(String dirPath)
Delete the directory.
- Parameters:
dirPath- The path of directory.
-
deleteFile
static boolean deleteFile(String srcFilePath)
Delete the file.
- Parameters:
srcFilePath- The path of source file.
-
deleteFile
static boolean deleteFile(File file)
Delete the file.
- Parameters:
file- The file.
-
deleteAllInDir
static boolean deleteAllInDir(String dirPath)
Delete the all in directory.
- Parameters:
dirPath- The path of directory.
-
deleteAllInDir
static boolean deleteAllInDir(File dir)
Delete the all in directory.
- Parameters:
dir- The directory.
-
deleteFilesInDir
static boolean deleteFilesInDir(String dirPath)
Delete all files in directory.
- Parameters:
dirPath- The path of directory.
-
deleteFilesInDir
static boolean deleteFilesInDir(File dir)
Delete all files in directory.
- Parameters:
dir- The directory.
-
deleteFilesInDirWithFilter
static boolean deleteFilesInDirWithFilter(String dirPath, FileFilter filter)
Delete all files that satisfy the filter in directory.
- Parameters:
dirPath- The path of directory.filter- The filter.
-
deleteFilesInDirWithFilter
static boolean deleteFilesInDirWithFilter(File dir, FileFilter filter)
Delete all files that satisfy the filter in directory.
- Parameters:
dir- The directory.filter- The filter.
-
listFilesInDir
static List<File> listFilesInDir(String dirPath)
Return the files in directory.
Doesn't traverse subdirectories
- Parameters:
dirPath- The path of directory.
-
listFilesInDir
static List<File> listFilesInDir(File dir)
Return the files in directory.
Doesn't traverse subdirectories
- Parameters:
dir- The directory.
-
listFilesInDir
static List<File> listFilesInDir(String dirPath, boolean isRecursive)
Return the files in directory.
- Parameters:
dirPath- The path of directory.isRecursive- True to traverse subdirectories, false otherwise.
-
listFilesInDir
static List<File> listFilesInDir(File dir, boolean isRecursive)
Return the files in directory.
- Parameters:
dir- The directory.isRecursive- True to traverse subdirectories, false otherwise.
-
listFilesInDirWithFilter
static List<File> listFilesInDirWithFilter(String dirPath, FileFilter filter)
Return the files that satisfy the filter in directory.
Doesn't traverse subdirectories
- Parameters:
dirPath- The path of directory.filter- The filter.
-
listFilesInDirWithFilter
static List<File> listFilesInDirWithFilter(File dir, FileFilter filter)
Return the files that satisfy the filter in directory.
Doesn't traverse subdirectories
- Parameters:
dir- The directory.filter- The filter.
-
listFilesInDirWithFilter
static List<File> listFilesInDirWithFilter(String dirPath, FileFilter filter, boolean isRecursive)
Return the files that satisfy the filter in directory.
- Parameters:
dirPath- The path of directory.filter- The filter.isRecursive- True to traverse subdirectories, false otherwise.
-
listFilesInDirWithFilter
static List<File> listFilesInDirWithFilter(File dir, FileFilter filter, boolean isRecursive)
Return the files that satisfy the filter in directory.
- Parameters:
dir- The directory.filter- The filter.isRecursive- True to traverse subdirectories, false otherwise.
-
getFileLastModified
static long getFileLastModified(String filePath)
Return the time that the file was last modified.
- Parameters:
filePath- The path of file.
-
getFileLastModified
static long getFileLastModified(File file)
Return the time that the file was last modified.
- Parameters:
file- The file.
-
getFileCharsetSimple
static String getFileCharsetSimple(String filePath)
Return the charset of file simply.
- Parameters:
filePath- The path of file.
-
getFileCharsetSimple
static String getFileCharsetSimple(File file)
Return the charset of file simply.
- Parameters:
file- The file.
-
getFileLines
static int getFileLines(String filePath)
Return the number of lines of file.
- Parameters:
filePath- The path of file.
-
getFileLines
static int getFileLines(File file)
Return the number of lines of file.
- Parameters:
file- The file.
-
getDirSize
static String getDirSize(String dirPath)
Return the size of directory.
- Parameters:
dirPath- The path of directory.
-
getDirSize
static String getDirSize(File dir)
Return the size of directory.
- Parameters:
dir- The directory.
-
getFileSize
static String getFileSize(String filePath)
Return the length of file.
- Parameters:
filePath- The path of file.
-
getFileSize
static String getFileSize(File file)
Return the length of file.
- Parameters:
file- The file.
-
getDirLength
static long getDirLength(String dirPath)
Return the length of directory.
- Parameters:
dirPath- The path of directory.
-
getDirLength
static long getDirLength(File dir)
Return the length of directory.
- Parameters:
dir- The directory.
-
getFileLength
static long getFileLength(String filePath)
Return the length of file.
- Parameters:
filePath- The path of file.
-
getFileLength
static long getFileLength(File file)
Return the length of file.
- Parameters:
file- The file.
-
getFileMD5ToString
static String getFileMD5ToString(String filePath)
Return the MD5 of file.
- Parameters:
filePath- The path of file.
-
getFileMD5ToString
static String getFileMD5ToString(File file)
Return the MD5 of file.
- Parameters:
file- The file.
-
getFileMD5
static Array<byte> getFileMD5(String filePath)
Return the MD5 of file.
- Parameters:
filePath- The path of file.
-
getFileMD5
static Array<byte> getFileMD5(File file)
Return the MD5 of file.
- Parameters:
file- The file.
-
getDirName
static String getDirName(File file)
Return the file's path of directory.
- Parameters:
file- The file.
-
getDirName
static String getDirName(String filePath)
Return the file's path of directory.
- Parameters:
filePath- The path of file.
-
getFileName
static String getFileName(File file)
Return the name of file.
- Parameters:
file- The file.
-
getFileName
static String getFileName(String filePath)
Return the name of file.
- Parameters:
filePath- The path of file.
-
getFileNameNoExtension
static String getFileNameNoExtension(File file)
Return the name of file without extension.
- Parameters:
file- The file.
-
getFileNameNoExtension
static String getFileNameNoExtension(String filePath)
Return the name of file without extension.
- Parameters:
filePath- The path of file.
-
getFileExtension
static String getFileExtension(File file)
Return the extension of file.
- Parameters:
file- The file.
-
getFileExtension
static String getFileExtension(String filePath)
Return the extension of file.
- Parameters:
filePath- The path of file.
-
-
-
-