How do I load a resource and use its contents as a string in Spring

前端 未结 5 1019
春和景丽
春和景丽 2020-12-04 17:48

How can I load a Spring resource contents and use it to set a bean property or pass it as an argument constructor?

The resource contains free text.

5条回答
  •  自闭症患者
    2020-12-04 18:11

    In one line try this to read test.xml:

    String msg = StreamUtils.copyToString( new ClassPathResource("test.xml").getInputStream(), Charset.defaultCharset()  );
    

提交回复
热议问题