类 UFile

java.lang.Object
com.gdxsoft.easyweb.utils.UFile

public class UFile extends Object
  • 构造器详细资料

    • UFile

      public UFile()
  • 方法详细资料

    • getExtFromFileBytes

      public static String getExtFromFileBytes(byte[] buf)
      Get the extension from the bytes of the file
      参数:
      buf - the bytes of the file
      返回:
      the file extension
    • delete

      public static boolean delete(String name)
      Delete a file
      参数:
      name - The file path and name
      返回:
      result
    • getFileExt

      public static String getFileExt(String name)
      Get the extension form the file name
      参数:
      name - the file name
      返回:
      the extension
    • getFileNoExt

      public static String getFileNoExt(String name)
      Get the file name without extension
      参数:
      name - the file name
      返回:
      the file name without extension
    • changeFileExt

      public static String changeFileExt(String name, String newExt)
      Change the file extension
      参数:
      name - the file's name and path
      newExt - new extension
      返回:
      new file name and path
    • getFiles

      public static File[] getFiles(String rootPath, String[] filter)
      Get the files in the parent directory according to the filter, excluding sub directories
      参数:
      rootPath - the parent directory
      filter - filter
      返回:
      the files
    • readFileGzipBase64

      public static String readFileGzipBase64(String path) throws IOException
      Convert the file to GZIP compressed base64 string
      参数:
      path - the file name and path
      返回:
      the result
      抛出:
      IOException
    • readFileBase64

      public static String readFileBase64(String path) throws IOException
      Convert the file to base64 string
      参数:
      path - the file name and path
      返回:
      the result;
      抛出:
      Exception
      IOException
    • readFileBytes

      public static byte[] readFileBytes(String path) throws IOException
      Read the binary contents of the file
      参数:
      path - the file name and path
      返回:
      binary contents
      抛出:
      IOException
    • readFileText

      public static String readFileText(String filePath) throws IOException
      Read the file contents(UTF8) from file or resource
      参数:
      filePath - the file name and path
      返回:
      the file contents (UTF8)
      抛出:
      IOException
    • readZipBytes

      public static byte[] readZipBytes(String zipFilePath, String innerFileName) throws IOException
      Read the zip/jar file binary (UTF8)
      参数:
      zipFilePath - the zip or jar file
      innerFileName - zip or jar inner path and name
      返回:
      the content of the file in the zip/jar
      抛出:
      IOException
    • getZipList

      public static List<String> getZipList(String zipFilePath) throws IOException
      Get the zip/jar file list
      参数:
      zipFilePath - the zip or jar file
      返回:
      The zip file list
      抛出:
      IOException
    • readZipText

      public static String readZipText(String zipFilePath, String innerFileName) throws IOException
      抛出:
      IOException
    • copyFile

      public static void copyFile(String fileFrom, String fileTo) throws IOException
      Copy file
      参数:
      fileFrom - from
      fileTo - to
      抛出:
      IOException
    • zipFile

      public static String zipFile(String filePath) throws IOException
      Compress the file with ZIP
      参数:
      filePath - the file name and path
      返回:
      the ZIP file name and path
      抛出:
      IOException
    • zipPath

      public static String zipPath(String path) throws IOException
      Compress the path with ZIP, exclude sub directories
      参数:
      path - the path
      返回:
      zipFileName the ZIP file name and path
      抛出:
      IOException
    • zipFiles

      public static void zipFiles(String[] files, String zipFileName) throws IOException
      Compress the files with ZIP
      参数:
      files - the file path and name array
      zipFileName - the ZIP file path and name
      抛出:
      IOException
    • zipPaths

      public static void zipPaths(String pathRoot, String zipFileName) throws IOException
      Compress all files in the root directory, including sub directories
      参数:
      pathRoot - the root directory
      zipFileName - the compressed ZIP file path and name
      抛出:
      IOException
    • zipFiles

      public static void zipFiles(File[] files, String zipFileName) throws IOException
      Compress files
      参数:
      files - the files array
      zipFileName - the compressed ZIP file path and name
      抛出:
      IOException
    • unZipFile

      public static List<String> unZipFile(String zipFilePath) throws IOException
      Unzip files to the zipFilePath.xxx.unzip dir
      参数:
      zipFilePath - the zip file path and name
      返回:
      list of unziped files
      抛出:
      IOException
    • unZipFile

      public static List<String> unZipFile(String zipFilePath, String targetPath) throws IOException
      Unzip files to the target dir
      参数:
      zipFilePath - the zip file path and name
      targetPath - the unziped dir
      返回:
      list of unziped files
      抛出:
      IOException
    • renameFile

      public static void renameFile(String sourcePathAndName, String newName)
      Rename the file
      参数:
      sourcePathAndName - the source file name and path
      newName - new file name (exclude path)
    • createHashTextFile

      public static String createHashTextFile(String content, String ext, String path, boolean isOverWrite) throws Exception
      Create a hash file based on the content
      参数:
      content - the content
      ext - the hash file extension
      path - the directory where the hash file is saved
      isOverWrite - whether to overwrite the hash file
      返回:
      the hash file name, exclude path
      抛出:
      Exception
    • createNewTextFile

      public static void createNewTextFile(String fileName, String content) throws IOException
      Create a new text file
      参数:
      fileName - the saved file name and directory
      content - the saved text content (UTF8)
      抛出:
      IOException
    • createMd5File

      public static String createMd5File(byte[] bytes, String ext, String path, boolean isOverWrite) throws Exception
      Create a binary file based on the MD5 of the binary content, and the saved file name is MD5 + extension
      参数:
      bytes - The binary content
      ext - The saved file extension
      path - The saved directory
      isOverWrite - Whether to overwrite
      返回:
      The saved file name (MD5 + extension), exclude directory
      抛出:
      Exception
    • createMd5File

      public static String createMd5File(byte[] bytes, String md5, String ext, String path, boolean isOverWrite) throws Exception
      Create a binary file based on the MD5 of the binary content, and the saved file name is MD5 + extension
      参数:
      bytes - The binary content
      md5 - The md5
      ext - The saved file extension
      path - The saved directory
      isOverWrite - Whether to overwrite
      返回:
      The saved file name (MD5 + extension), exclude directory
      抛出:
      Exception
    • createMd5

      public static String createMd5(File file)
      Get the MD5 of the file
      参数:
      file - the file
      返回:
      the MD5 of the file (hex)
    • md5

      public static String md5(File file)
      Get the MD5 of the file
      参数:
      file - the file
      返回:
      the MD5 of the file (hex)
    • sha1

      public static String sha1(File file)
      Get the MD5 of the file
      参数:
      file - the file
      返回:
      the MD5 of the file (hex)
    • sha256

      public static String sha256(File file)
      Get the MD5 of the file
      参数:
      file - the file
      返回:
      the MD5 of the file (hex)
    • digestFile

      public static String digestFile(File file, String digestName)
      Get the digest of the file
      参数:
      file - the file
      digestName - the digest name (MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512)
      返回:
      the digest (hex)
    • createBinaryFile

      public static void createBinaryFile(String path, byte[] bytes, boolean isOverWrite) throws Exception
      Create a binary file
      参数:
      path - The file name and path to be created
      bytes - The saved binary
      isOverWrite - Whether to overwrite
      抛出:
      Exception
    • createUnGZipHashFile

      public static String createUnGZipHashFile(String base64String, String ext, String path, boolean isOverWrite) throws Exception
      Convert GZIP compressed BASE64 encoded string into a file
      参数:
      base64String - the BASE64 encoded string
      ext - The file extension
      path - The directory of the file is saved
      isOverWrite - Whether to overwrite
      返回:
      the create file name, exclude path
      抛出:
      Exception
    • createSplitDirPath

      public static String createSplitDirPath(String name, int len)
      Split file name or directory name based on the name
      参数:
      name - name
      len - split length
      返回:
      the result
    • buildPaths

      public static boolean buildPaths(String path)
      Create the paths
      参数:
      path - the path
      返回:
      result