iscomar001
11/30/2018 - 11:13 PM

Portapapeles

Portapapeles desde java

public static List<String> getPortapapeles() throws Exception {
    String cadena = "";
    List<String> lista = new ArrayList();
    try {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable transferable = clipboard.getContents(null);
        if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            cadena = (String) transferable.getTransferData(DataFlavor.stringFlavor);

        }
        String[] cadenas = cadena.split("\n");
        for (int i = 0; i < cadenas.length; i++) {
            lista.add(cadenas[i]);
        }
    } catch (Exception exception) {
        String strError = "Error al obtener los datos del portapapeles";
        logger.error(strError + "--ERROR= " + exception.getMessage());
        throw new Exception(strError);
    }
    return lista;
}