Class FileUtils

java.lang.Object
cool.scx.common.util.FileUtils

public final class FileUtils extends Object
文件 操作类
Version:
0.0.1
Author:
scx567888
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • delete

      public static void delete(Path start, boolean excludeRoot) throws IOException
      删除文件或文件夹
      Parameters:
      start - 起始目录
      excludeRoot - 实现清空文件夹的效果 排除根目录 (删除文件为 "文件" 时无效, "目录" 时有效) 比如 未使用此选项调用 delete("/user/test") 文件夹 则 test 文件夹会被删除 若使用此选项则 会清空 test 下所有文件 test 目录则会保留
      Throws:
      IOException - e
    • delete

      public static void delete(Path start) throws IOException
      Throws:
      IOException
    • move

      public static void move(Path source, Path target, CopyOption... options) throws IOException
      本质上就是调用 Files.move(Path, Path, CopyOption...) ,但是在之前会创建不存在的父目录
      Parameters:
      source - a
      target - a
      options - a
      Throws:
      IOException - a
    • copy

      public static void copy(Path source, Path target, CopyOption... options) throws IOException
      本质上就是调用 Files.copy(Path, Path, CopyOption...) ,但是在之前会创建不存在的父目录
      Parameters:
      source - a
      target - a
      options - a
      Throws:
      IOException - a
    • write

      public static void write(Path path, byte[] bytes, OpenOption... options) throws IOException
      本质上就是调用 Files.write(Path, byte[], OpenOption...) ,但是在之前会创建不存在的父目录
      Parameters:
      path - a
      bytes - a
      options - a
      Throws:
      IOException - a
    • getHeadAsHex

      public static String getHeadAsHex(String filePath, int length) throws IOException
      Throws:
      IOException
    • getHead

      public static byte[] getHead(String filePath, int length) throws IOException
      Throws:
      IOException
    • getFileName

      public static String getFileName(String path)
      获取文件名
      Parameters:
      path - a
      Returns:
      a
    • getExtension

      public static String getExtension(String path)
      获取拓展名 (不包括 . ) 例 : "cat.png" 会获得 "png"
      Parameters:
      path - a String object
      Returns:
      a String object
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(String path)
      获取文件名 (不包括拓展名 ) 例 : "cat.png" 会获得 "cat"
      Parameters:
      path - a String object
      Returns:
      a String object
    • longToDisplaySize

      public static String longToDisplaySize(long size)
      将 long 类型的文件大小 格式化(转换为人类可以看懂的形式) 如 1024 转换为 1KB
      Parameters:
      size - a long.
      Returns:
      a String object.
    • displaySizeToLong

      public static long displaySizeToLong(String str)
      将 格式化后的大小转换为 long 如将 1KB 转换为 1024
      Parameters:
      str - 待转换的值 如 5MB 13.6GB
      Returns:
      a long.
    • merge

      public static void merge(Path source, Path target) throws IOException
      Throws:
      IOException
    • appendToFile

      public static void appendToFile(Path target, InputStream appendContent) throws IOException
      Throws:
      IOException