The Java language Operator Reader jdk1.6 provides a package javax.smartcardio that connects directly to the PCSC reader, and to the reader for instruction Interaction
Package Javax.smartcardio More Information
Http://docs.oracle.com/javase/6/docs/jre/api/security/smartcardio/spec/javax/smartcardio/package-summary.html
Java language Code Instance
/**
*connectpcsc.java
*/
Import java.util.List;
Import javax.smartcardio.CardTerminal;
Import Javax.smartcardio.TerminalFactory;
public class CONNECTPCSC {
/**
* Main function, listing all the PC/SC readers connected to your PC
*/
public static void Main (string[] args) {
Show the list of available terminals
Terminalfactory factory = Terminalfactory.getdefault ();
List of readers (empty)
List<cardterminal> terminals;
try {
Get list of readers form the terminal
Terminals = Factory.terminals (). List ();
Print List of readers to the console.
System.out.println (Terminals.tostring ());
} catch (Exception e) {
Print Stack-trace in case of an error
E.printstacktrace ();
}
}
}
Import java.util.List;
Import Javax.smartcardio.Card;
Import Javax.smartcardio.CardChannel;
Import javax.smartcardio.CardException;
Import javax.smartcardio.CardTerminal;
Import Javax.smartcardio.CommandAPDU;
Import Javax.smartcardio.ResponseAPDU;
Import Javax.smartcardio.TerminalFactory;
public class GetStatus {
public static void Main (string[] args) {
Terminalfactory factory = Terminalfactory.getdefault ();
try {
list<cardterminal> terminal = factory.terminals (). List ();
System.out.println ("Terminal:" + terminal);
Cardterminal ter = terminal.get (0);
Establish a connection with the card
Card = Ter.connect ("t=0");
System.out.println ("card:" + card);
Cardchannel channel = Card.getbasicchannel ();
RESPONSEAPDU r = channel.transmit (new COMMANDAPDU (160, 242, 0, 0, 22)); A0 F2 00 00 16
SYSTEM.OUT.PRINTLN ("Response:" + r.tostring ());
for (int j=0; j<8; J + +) {
System.out.print (integer.tohexstring ((int) ((R.getdata () [j]+256]% 256) + "");
}
System.out.print ("\ n");
for (int j=0; J<card.getatr (). GetBytes (). length; J + +) {
System.out.print (integer.tohexstring ((int) ((Card.getatr () getBytes () [j]+256)% 256)] + "");
}
Disconnect
Card.disconnect (FALSE);
} catch (Cardexception e) {
TODO auto-generated Catch block
SYSTEM.OUT.PRINTLN ("Connection Erro,or card not inserted.");
}
}
}
jdk1.6 Java language Connection PCSC reader sends APDU instructions