Here is another take on this. Instead of trying to get too fancy, it prints via WordPad using Shell in the manner you wanted to print via Print.exe:
<path to wordpad>\wordpad.exe /p "<path and file>"
My understanding is that if you can jump through all of the hoops to use javax.print then it would be possible to raise a printer selection dialog to obtain a desired printer name, which would allow you to use:
<path to wordpad>\wordpad.exe /pt "<path and file>" "printer name"
Some really bizarre design decisions seem to have been made when many of the official Java libraries were created.
However as things are in my demo it just prints to the user's default printer.
Why WordPad and not Notepad? Well here we get down to B4J (Java) compromise #1: the notion that text file lines should be LF delimited rather than CRLF. Notepad doesn't cope well, while Wordpad shrugs it off.
There are other frustrating B4J compromises that I believe will ultimately hurt it as a language for many programmers. Some stem from B4J's javaesque nature, others due to B4J implementation decisions that probably go back to B4A, and others are due to design decisions made when 3rd party contributed B4J libraries were designed. There are comments in the code of this small demo that call out some of these issues that result in a lot of extra code required to accomplish trivial things.
Feel free to ignore these comments. They are not there as criticisms or because I hope or expect things to change, but as reminders to myself when I have to reinvent these wheels in future programs.
The demo:
This program has a Form with 3 buttons and a hacked-together "status bar" (there must be a better way, even if a JavaFX Label could have borders we'd be far ahead of the game).
Click the first button and a text file "report" is created as a temporary text file.
Click the second button to build the path to WordPad and shell it to print the temporary file.
Click the third button to remove the temporary file.
In case anyone is curious, it also shows one quick and dirty way to retrieve the value of an environment variable.