Package 

Class FileUtils


  • 
    public final class FileUtils
    
                        

    Author: bin.yang Maintainer: bin.yang Date: 2019/6/29 0029 Copyright: 2019 Inc. All rights reserved. Desc: 文件操作

    • 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.
      • isFile

         static boolean isFile(File file)

        Return whether it is a file.

        Parameters:
        file - The 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.
      • delete

         static boolean delete(File file)

        Delete the directory.

        Parameters:
        file - The file.
      • deleteDir

         static boolean deleteDir(String dirPath)

        Delete the directory.

        Parameters:
        dirPath - The path of directory.
      • deleteDir

         static boolean deleteDir(File dir)

        Delete the directory.

        Parameters:
        dir - The 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.
      • 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.
      • 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.