i want to access default printer port in java.
also, i want to know that is default printer inkjet, laser, dotmetrix etc. please provide me with reference.
Thanks. Muhammad Babar Nazir Software Engineer
i want to access default printer port in java.
also, i want to know that is default printer inkjet, laser, dotmetrix etc. please provide me with reference.
Thanks. Muhammad Babar Nazir Software Engineer
I'm guessing that you are using windows. In such case you can query the windows registry to find the default printer port. All the system information is the Preferences.
import java.util.prefs.Preferences;
....
Preferences userRoot = Preferences.userRoot();
Preferences systemRoot = Preferences.systemRoot();
There is a good article that explain how to do that using pure java:
http://lenkite.blogspot.com/2008/05/access-windows-registry-using-java.html?dzref=85420
Also, you may need to know the key of the default printer in windows:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
Do you actually need the port number ? If you want to print from Java, have you considered the Java Printing APIs ?
The reason that I ask is that you may not have a printer attached directly. You may have a networked printer. The JPA will provide you with a more reliable interface for this.