Skip to main content
2 of 2
added 316 characters in body
mdma
  • 57.9k
  • 12
  • 97
  • 128

You will need to load the file using the Class.getResourceAsStream() method

E.g.

InputStream str = getClass().getResourceAsStream("/UPDATE.txt"); 

Or if you are in a static method, then specify the class explicitly

InputStream str = MyApp.class.getResourceAsStream("/UPDATE.txt"); 

EDIT:

With a StreamSource, just pass the input stream into the stream source, e.g.

 new StreamSource(getClass().getResourceAsStream("/UPDATE.txt")); 

But watch out, getResourceAsStream returns null if the resource doesn't exist, so you might want to explicitly check for that and throw an exception.

mdma
  • 57.9k
  • 12
  • 97
  • 128