在写项目的时候,用绝对路径来写入json文件
filePath="D:\zyx-gitStudy\class\GPT\GPTxm\src\main\resources\dialog_content.json"
Files.writeString(filePath, dialogContent, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
然后在javaspring,读取打印出来,却是覆盖前的文件内容。
然后我找到了
Resource resource = new ClassPathResource("dialog_content.json");
Path path = resource.getFile().toPath();
在Spring框架中,ClassPathResource
是一个用于加载类路径(classpath)下的资源的类。当你有一个ClassPathResource
对象时,你需要提供一个字符串参数,这个字符串创建是资源在类路径下的路径。
这个就相当于放到了缓存区,只要修改了,就会重启javaspring。还是很好用的