JSON生成文件并设置文件可读
String times = HutoolDateUtil.timeEmpty(HutoolDateUtil.nowDateTime());
String title = "dangerousCarRecord-" + times + ".json";
File file = new File("/home/ftp/" + title);
FileUtil.FilePermission(file);
objectMapper.writeValue(file, list);
log.info("JSON file created successfully:危险品车");
@Slf4j
public class FileUtil {
/**
* @description 设置文件可读
* @author wangxiang
* @date 2023/10/16
*/
public static void FilePermission(File file) {
try {
if (file.createNewFile()) {
System.out.println("file name = " + file.getName());
Runtime runtime = getRuntime();
runtime.exec("chmod 777 /home/ftp/" + file.getName());
// System.out.println("File is created!");
// file.setExecutable(true);//设置可执行权限
// file.setReadable(true);//设置可读权限
// file.setWritable(true);//设置可写权限
} else {
System.out.println("File already exists.");
}
} catch (Exception e) {
log.error("{}", e.getMessage());
}
}
}