Capture clipboard in Windows with JAVA

3

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.

    
asked by anonymous 19.06.2015 / 15:42

1 answer

5

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:

19.06.2015 / 16:01