以下程序是一个输出剪贴板中文本内容的程序,有志之士一起讨论下:
import java.awt.*;
import java.awt.datatransfer.*;
import java.io.*;
public class Jiantieban{
public static void main(String[] args){
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try { if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor))
{
String a = (String) t.getTransferData(DataFlavor.stringFlavor);
System.out.println(a);
}
} catch (UnsupportedFlavorException ex)
{
ex.printStackTrace();
} catch (IOException ex)
{
ex.printStackTrace();
}
}
}
|