linux和window读取文件遇到的坑
最开始读写文件我都是用的FileInputStream、FileOutputStream在window系统测试完全没问题,jar包上传到linux直接说找不到文件,后面用ClassPathResource、FileSystemResource读写文件保证两个系统都适用。
代码里那种写方式会在项目根路径生成相同名称的文件,这个文件在代码执行结束后就没用了,直接删除。废话不多说,直接上代码,下面是正确无误的代码:
package com.common.util;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.WritableResource;
import org.yaml.snakeyaml.Yaml;
import java.io.*;
import java.util.Map;
@Slf4j
public class YmlUtil {
/**
* 解析yml配置文件:读写操作
*/
public static void resolveDefaultZone() {
//加解密工具类
StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor(