类 FileUtil

java.lang.Object
com.weicoder.common.io.FileUtil
直接已知子类:
I.F

public sealed class FileUtil extends Object permits I.F
对文件进行一些处理。
作者:
WD
  • 构造器详细资料

    • FileUtil

      public FileUtil()
  • 方法详细资料

    • mkdirs

      public static boolean mkdirs(String path)
      创建目录
      参数:
      path - 目录路径
      返回:
      true 成功 false 失败
    • exists

      public static boolean exists(String name)
      文件是否存在
      参数:
      name - 文件名
      返回:
      true 存在 false 不存在
    • delete

      public static boolean delete(String fileName)
      删除文件
      参数:
      fileName - 文件名
      返回:
      true 成功 false 失败
    • delete

      public static boolean delete(File file)
      删除文件
      参数:
      file - 文件名
      返回:
      true 成功 false 失败
    • copy

      public static long copy(String src, String target)
      复制文件
      参数:
      src - 原文件
      target - 目标文件
      返回:
      写入成功字节数
    • copy

      public static long copy(File src, File target)
      复制文件
      参数:
      src - 原文件
      target - 目标文件
      返回:
      写入成功字节数
    • readString

      public static String readString(String fileName)
      读取文件 默认使用UTF-8编码
      参数:
      fileName - 要读取的文件
      返回:
      String 读取出的字符串
    • readString

      public static String readString(String fileName, String charsetName)
      读取文件
      参数:
      fileName - 要读取的文件
      charsetName - 编码格式
      返回:
      读取文件的内容
    • read

      public static byte[] read(String fileName, long pos, long len)
      读取文件为字节数组 可指定开始读取位置
      参数:
      fileName -
      pos -
      len -
      返回:
    • read

      public static long read(String name, Calls.EoV<Buffer> call)
      以流模式分段读取文件 使用默认IO缓冲和默认IO模式
      参数:
      name - 文件名
      call - 回调
      返回:
      读取长度
    • read

      public static long read(String name, int buff, Calls.EoV<Buffer> call)
      以流模式分段读取文件 使用默认IO缓冲和默认IO模式
      参数:
      name - 文件名
      buff - 每次读取的自己缓冲数
      call - 回调
      返回:
      读取长度
    • read

      public static byte[] read(String fileName, long pos)
      读取文件为字节数组 可指定开始读取位置
      参数:
      fileName - 文件名
      pos - 偏移
      返回:
      字节数组
    • read

      public static byte[] read(String fileName)
      读取文件
      参数:
      fileName - 要读取的文件
      返回:
      读取文件字节数组
    • read

      public static byte[] read(File file)
      读取文件
      参数:
      file - 要读取的文件
      返回:
      读取文件字节数组
    • convert

      public static long convert(String read, String write, Calls.EoR<Buffer,Buffer> call)
      转换文件 读取文件并写入指定文件 按缓冲字节写入
      参数:
      read - 读取文件
      write - 写入文件
      call - 回调
      返回:
      读取长度
    • write

      public static long write(String fileName, InputStream is)
      把InputStream流中的内容保存到文件中
      参数:
      fileName - 文件名
      is - 流
      返回:
      写入成功字节数
    • write

      public static long write(String fileName, File file)
      把文件写指定路径中
      参数:
      fileName - 文件名
      file - 文件
      返回:
      写入成功字节数
    • write

      public static long write(String fileName, byte[] b)
      把文件写指定路径中
      参数:
      fileName - 文件名
      b - 字节数组
      返回:
      写入成功字节数
    • write

      public static long write(String fileName, byte[] b, boolean append)
      把文件写指定路径中
      参数:
      fileName - 文件名
      b - 字节数组
      append - 是否追加
      返回:
      写入成功字节数
    • write

      public static void write(String fileName, byte[] b, long pos)
      把字节写到文件中 可指定写入位置
      参数:
      fileName - 文件名
      b - 字节数组
      pos - 偏移
    • write

      public static long write(String fileName, String text)
      写文件 默认使用UTF-8编码
      参数:
      fileName - 文件名
      text - 写入的内容
      返回:
      true false
    • write

      public static long write(String fileName, String text, boolean append)
      写文件 默认使用UTF-8编码
      参数:
      fileName - 文件名
      text - 写入的内容
      append - 是否追加
      返回:
      true false
    • write

      public static long write(String fileName, String text, String charsetName)
      写文件
      参数:
      fileName - 文件名
      text - 写入的内容
      charsetName - 编码格式
      返回:
      写入成功字节数
    • write

      public static long write(String fileName, String text, String charsetName, boolean append)
      写文件
      参数:
      fileName - 文件名
      text - 写入的内容
      charsetName - 编码格式
      append - 是否追加
      返回:
      写入成功字节数
    • newFile

      public static File newFile(String fileName)
      获得文件
      参数:
      fileName - 文件名含路径
      返回:
      File对象
    • newFile

      public static File newFile(URI uri)
      获得文件
      参数:
      URI - uri 文件名含路径
      返回:
      File对象
    • getRandomAccessFile

      public static RandomAccessFile getRandomAccessFile(String fileName, String mode, long pos)
      获得文件
      参数:
      fileName - 文件名含路径
      mode - 打开模式
      pos - 偏移
      返回:
      RandomAccessFile对象
    • in

      public static FileInputStream in(String fileName)
      获得文件输入流 如果失败返回null
      参数:
      fileName - 文件名
      返回:
      输入流
    • getInputStream

      public static FileInputStream getInputStream(String fileName)
      获得文件输入流 如果失败返回null
      参数:
      fileName - 文件名
      返回:
      输入流
    • out

      public static FileOutputStream out(String fileName)
      获得文件输出流 如果失败返回null
      参数:
      fileName - 文件名
      返回:
      输出流
    • getOutputStream

      public static FileOutputStream getOutputStream(String fileName)
      获得文件输出流 如果失败返回null
      参数:
      fileName - 文件名
      返回:
      输出流
    • getOutputStream

      public static FileOutputStream getOutputStream(String fileName, boolean append)
      获得文件输出流 如果失败返回null
      参数:
      fileName - 文件名
      append - 是否追加
      返回:
      输出流
    • getInputStream

      public static FileInputStream getInputStream(File file)
      获得文件输入流 如果失败返回null
      参数:
      file - 文件
      返回:
      输入流
    • getOutputStream

      public static FileOutputStream getOutputStream(File file)
      获得文件输出流 如果失败返回null
      参数:
      file - 文件
      返回:
      输出流
    • getOutputStream

      public static FileOutputStream getOutputStream(File file, boolean append)
      获得文件输出流 如果失败返回null
      参数:
      file - 文件
      append - 是否追加
      返回:
      输出流