解决 class path resource [xx] cannot be resolved to absolute file path because it does not reside

class path resource [xx] cannot be resolved to absolute file path because it does not reside
发布线上之后出现的问题,查询资源发现是因为代码中直接调用getFIle()造成的问题。

ClassPathResource classPathResource = new ClassPathResource("xxx/xxx.txt");
File outFile = classPathResource.getFile();

我直接新建一个临时文件File来读取这个

	// 我命油腻 不油天
	File outFile = new File("x.txt");
	//通过流写入到FIle对象中
	InputStream in= classPathResource.getInputStream();
	// 怎么转就比较方便了
	// 操作完成之后
	if(outFile.exists()){
		outFile.delete();
	}
posted @ 2023-07-06 21:38  搬砖的孟达  阅读(1763)  评论(0)    收藏  举报  来源