ChopperBot ChopperBot
首页
  • 快速开始
  • 开发指南
  • 技术文档
  • 使用配置
生态
问答
💖支持
🚀起飞诶~~起飞
更新日志 (opens new window)
GitHub (opens new window)
首页
  • 快速开始
  • 开发指南
  • 技术文档
  • 使用配置
生态
问答
💖支持
🚀起飞诶~~起飞
更新日志 (opens new window)
GitHub (opens new window)
  • 模块文档

    • common

      • common目录
    • FileModule

      • FileModule目录
        • FileCache
        • FileUtil
        • JsonFileUtil
      • FileCache
    • BarrageModule

    • AccountModule

    • CreeperModule

    • HotModule

目录

FileModule目录

👉 源码 (opens new window)

  • FileCache
  • FileUtil
  • JsonFileUtil

# FileCache

说明

由于ChopperBot中使用了大量的Json文件来保存配置或数据,而有些Json文件可能会被频繁的操作, 而FileCache就是用来解决文件的频繁写入造成的IO问题,FileCache具备了简单的文件操作功能,文件缓存池,文件刷入,文件定时刷入,文件版本对照功能, 方便开发人员对文件的操作与管理。

更多详情请移步至 FileCache 查看。

# FileUtil

说明

文件的操作工具类

方法名称 方法说明 参数描述 返回内容
isFileExist 判断文件是否存在 dir(String) 文件路径 boolean
copyFile 复制文件 srcPath(String) 源文件路径,destPath(String) 目标文件路径 File
deleteFile 删除文件 path(String) 文件根路径, filename(String) 文件名称 boolean
deleteFile 删除文件 path(String) 文件路径 boolean
deleteDirectory 删除文件夹,包括文件夹内容
(排除root文件和C:)
path(String) 文件路径 boolean
deleteDirectory 删除文件夹,包括文件夹内容 path(String) 文件路径
visit 访问文件时触发该方法
preVisit 访问子目录前触发该方法
postVisit 访问目录之后触发该方法
boolean
public void testDelete() throws IOException {
        FileUtil.deleteDirectory("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\trash");
}
1
2
3
  • 更多例子可查看test包下面的samples
  • FileUtilTest (opens new window)

# JsonFileUtil

说明

Json文件的操作工具类

方法名称 方法说明 参数描述 返回内容
readJsonFile 读取json文件 filePath(String) 文件根路径
fileName(String) 文件名
Map
readJsonFile 读取json文件 fullPath(String) 全文件路径
Map
readJsonFileToJSONObject 读取json文件并返回json对象 filePath(String) 文件根路径
fileName(String) 文件名
JsonObject
readJsonFileToJSONObject 读取json文件并返回json对象 fullPath(String) 全文件路径
JsonObject
readJsonFileToObject 读取json文件并返回对象 fullPath(String) 全文件路径
clazz(Class) 返回类型
T泛型
writeJsonFile 写入json文件,不存在则自动创建 filePath(String) 文件路径
fileName(String) 文件名
data(Map) 内容
File
writeJsonFile 写入json文件,不存在则自动创建 fullPath(String) 全文件路径
data(Map) 内容
File
writeJsonFileIsExist 写入json文件,不存在则返回null filePath(String) 文件路径
fileName(String) 文件名
data(Map) 内容
File
writeJsonFileIsExist 写入json文件,不存在则返回null fullPath(String) 全文件路径
data(Map) 内容
File
writeBigJsonFile 写入大json文件 fullPath(String) 全文件路径
data(Map) 内容
File
writeBigJsonFile 写入大json文件 fullPath(String) 全文件路径
Objs(List) 内容
File
public void writeClassInJsonFile() {
        Student student = new Student(
        "Genius",
        18,
        "HUST",
        "CS",
        List.of("Coding", "Reading", "Playing"),
        Map.of("QQ", "123456789", "WeChat", "987654321")
        );
        JsonFileUtil.writeJsonFile("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\", "student.json", student);
        JsonFileUtil.writeBigJsonFile("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\student2.json", List.of(student));
        JsonFileUtil.writeJsonFileIsExist("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\student3.json", student);

        System.out.println(JsonFileUtil.readJsonFileToObject("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\student.json", Student.class));
        System.out.println(JsonFileUtil.readJsonFileToObject("E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\student2.json",List.class));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • 更多例子可查看test包下面的samples
  • JsonFileUtilTest (opens new window)
帮助我们改善此页面! (opens new window)
上次更新: 2023/07/31, 18:39:11
common目录
FileCache

← common目录 FileCache→

Theme by Vdoing | Copyright © 2016-2023 TimeMachine Lab | Sponsored by JetBrains | 渝ICP备2021000141号-1

友情链接:GeniusBlog

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式