SpringBoot 读取 resources 里的静态文件
//存在windows/Linux服务器上的相对路径的文件夹 String path = "/fonts"; //判断文件夹是否存在存在不做任何操作,不存在则新建 if(!new File(path).exists()) { boolean mkdirs = new File(path).mkdirs(); if(!mkdirs){ } } //读取resources目录下的文件为流! 我这里使用的fonts是resources里的文件夹 InputStream stream = this.getClass().getClassLoader().getResourceAsStream("fonts/simhei.ttf"); //将流复制到相对路径内 Files.copy(stream, Paths.get("/fonts/simhei.ttf")); //new File() 相对路径里的文件 File file= new File("/fonts/simhei.ttf");
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/218883.html原文链接:https://javaforall.net
