I'm not sure if you know that you can call
Desktop#print without opening a document first. If you do need to actually display it on the desktop first, then you will need to call
Desktop#open as you have in your example.
Closing it is not simple because you don't know the PID for the launched application. If you were able to guess which application associated with the file got launched (such as
notepad.exe for
.txt files), running something like
taskkill /IM notepad.exe (or the equivlent for other operating systems) using
Runtime#exec, you would end-up killing all processes running that same application, not just the intended one.