URL url = GzsmServiceImpl.class.getClassLoader().getResource("file/" + "GZSM.doc");
String path = url.getPath();
String path = ResourceUtils.getURL("classpath:").getPath() + "/file/GZSM.doc";
//创建临时路径
String tempDirPath = FilenameUtils.concat(FileUtils.getTempDirectory().getPath(), UUID.randomUUID().toString());
logger.info("临时文件夹路径为 : " + tempDirPath);
Thread.currentThread().getContextClassLoader().getResource("…").getPath()
this.getClass().getClassLoader().getResource("…").getPath()
XXX.class.getClassLoader().getResource("…").getPath()
ClassLoader.getSystemClassLoader().getResource("…").getPath()
ClassLoader.getSystemResource("…").getPath()
resour路径_全局路径
资源加载与临时文件管理:Java中类加载器路径探索
于 2021-12-29 18:41:14 首次发布
本文探讨了Java中不同类加载器获取资源路径的方法,如GzsmServiceImpl、ResourceUtils和Thread.currentThread().getContextClassLoader(),并展示了如何创建临时文件夹。重点在于理解ClassLoader在文件路径处理中的作用。
2635

被折叠的 条评论
为什么被折叠?



