工作中临时用到,记录下
//获取当前服务启动的目录
private static final String rootPath = System.getProperty("user.dir").replace("\\", "/");
private void checkFileExist(String module) {
String path = rootPath + File.separatorChar + "storage" + File.separatorChar + module + File.separatorChar;
log.info("判断文件是否存在 path:{}",path);
try {
File offsetFile = new File(path + "offset.dat");
//判断路径是否存在,不存在则创建
if(!offsetFile.getParentFile().exists()){
//创建父路径
offsetFile.getParentFile().mkdirs();
}
//判断文件是否存在
if (!offsetFile.exists()) {
log.info("文件不存在,准备创建文件");
offsetFile.createNewFile();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}