You can construct the parser instance with an InputStream. This page shows you how to create the InputStream, How does one create an InputStream from a String?
Then you can construct your parser with this as defined in the JavaCC API.
TheParser.TheParser(java.io.InputStream stream)
Do notice though:
This constructor is available only when both the options USER_TOKEN_MANAGER and USER_CHAR_STREAM are false. If the option STATIC is true, this constructor (along with other constructors) can be called exactly once to create a single parser object.
https://javacc.java.net/doc/apiroutines.html
You set these options in the option_bindings. https://javacc.java.net/doc/javaccgrm.html