我有一个 Spring Boot v2.1.2.RELEASE 应用程序。
我在 ../src/main/resources/icons/128/black/ae.png
我想阅读,但我收到错误:无法理解连接的 URL
@SpringBootApplication
public class SvgManagerApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SvgManagerApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
try {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document doc = f.createDocument("classpath:icons/128/black/ae.svg");
System.out.println(doc);
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
最佳答案
您可以尝试通过以下方式获取路径:
String path = SvgManagerApplication.class.getClassLoader().getResource("icons/128/black/ae.svg").getPath();
关于java - 无法理解读取 svg 文件的连接 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54530232/