Java Example Program / Sample Source Code
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 RetrieveText {
public static void main(String[] args) throws Exception {
Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard()
.getContents(null);
try {
if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String str = (String) transferable.getTransferData(DataFlavor.stringFlavor);
System.out.println(str);
}
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} |
|
|