1. Reading from the system clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
String buf;
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
{
try
{
buf=(String)contents.getTransferData(DataFlavor.stringFlavor);
}
catch (Exception e) {e.printStackTrace();}
}
2. Writing to the system clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
{
clipboard.setContents(new StringSelection(tag),null);
}