Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

public class Main {
    public static void main(String[] args) throws Exception {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable tran = clipboard.getContents(null);

        if (tran != null && tran.isDataFlavorSupported(DataFlavor.stringFlavor)) {

            String clipboardContent = (String) tran.getTransferData(DataFlavor.stringFlavor);

            System.out.println(clipboardContent);
        }
    }
}