clamp clamp - 1 year ago 81
Java Question

Get readable text only from clipboard

I already know how to get plain text from the clipboard in Java, but sometimes the text is encoded in some weird

, like when copying from Microsoft Word or from a website or even source code from Eclipse.

How to extract pure plain text from these

Answer Source
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;

String data = (String) Toolkit.getDefaultToolkit()

with the getData() Method and the stringFlavor you should get plain Text from the clipboard.

if there are weird text in the clipboard, i think, this should a problem of the programm which puts the data in the clipboard.