Java examples for Native OS:Clipboard
Retrieving Text from the System Clipboard
import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; public class Main { public static void main(String[] args) throws Exception { Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(null);// www . j a v a 2 s. co m try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { String s = (String) t.getTransferData(DataFlavor.stringFlavor); System.out.println(s); } } catch (UnsupportedFlavorException e) { } catch (IOException e) { } } }