Is there a way to capture the clipboard in a Windows environment with Java?
I can capture the screen, but I would like to capture the clipboard (that's what stays in memory when doing CTRL + C, for example).
A simple tip is enough for me.
Is there a way to capture the clipboard in a Windows environment with Java?
I can capture the screen, but I would like to capture the clipboard (that's what stays in memory when doing CTRL + C, for example).
A simple tip is enough for me.
Yes, you can do this using the Toolkit class. Here's an example:
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
String data = (String) Toolkit.getDefaultToolkit()
.getSystemClipboard().getData(DataFlavor.stringFlavor);
The method getData()
and stringFlavor
return pure Clipboard text.
More information: