#better ways to load xml as a string?

1 messages · Page 1 of 1 (latest)

remote spire
#

hey guys. i want to load xml as a string. im doing it this way:

String requestBodyTemplate = new String(Files.readAllBytes(Paths.get("src/main/resources/accountStatementRequestBodyTemplate.xml")));

and some people on the internet told me there are better ways, but they didnt explain to me. can smb help me out? thanks

sharp martenBOT
#

This post has been reserved for your question.

Hey @remote spire! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

exotic lagoon
#

If you package your application, it will likely not be available any more

#

It is a resource so you should access it as such

#

using getClass().getClassLoader().getResource("accountStatementRequestBodyTemplate.xml")

remote spire
sharp martenBOT
remote spire
#

but now idk what to use. so many choices

exotic lagoon
#

depends on the situation

remote spire
#

can u elaborate?

exotic lagoon
#

In most cases, I'd use Class#getResource or similar

remote spire
exotic lagoon
#

getClass().getClassLoader().getResource("accountStatementRequestBodyTemplate.xml")

#

or getClass().getClassLoader().getResourceAsStream("accountStatementRequestBodyTemplate.xml")

remote spire
#

i dont understand

exotic lagoon