I have a unit test that needs to work with XML file located in src/test/resources/abc.xml. What is the easiest way just to get the content of the file into String?
I have a unit test that needs to work with XML file located in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Finally I found a neat solution, thanks to Apache Commons:
Works perfectly. File
src/test/resources/com/example/abc.xmlis loaded (I’m using Maven).If you replace
"abc.xml"with, say,"/foo/test.xml", this resource will be loaded:src/test/resources/foo/test.xmlYou can also use Cactoos: