Spring Boot access static resources missing scr/main/resources

前端 未结 8 513
别那么骄傲
别那么骄傲 2020-12-04 16:39

I am working on a Spring Boot application. I need to parse an XML file (countries.xml) on start. The problem is that I do not understand where to put it so that I could acce

8条回答
  •  难免孤独
    2020-12-04 16:52

    You can use following code to read file in String from resource folder.

    final Resource resource = new ClassPathResource("public.key");
    String publicKey = null;
    try {
         publicKey = new String(Files.readAllBytes(resource.getFile().toPath()), StandardCharsets.UTF_8);
    } catch (IOException e) {
         e.printStackTrace();
    }
    

提交回复
热议问题