当前位置 : 主页 > 编程语言 > c++ >

Java获取系统剪贴板字符串内容

来源:互联网 收集:自由互联 发布时间:2021-07-03
gistfile1.txt import java.awt.Toolkit;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable;public static String getCliboardText() throws Exception {Clipboard sysClb = null;
gistfile1.txt
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

public static String getCliboardText() throws Exception {
	Clipboard sysClb = null;
	sysClb = Toolkit.getDefaultToolkit().getSystemClipboard();
	Transferable clipTf = sysClb.getContents(null);
	return clipTf.getTransferData(DataFlavor.stringFlavor).toString().trim();

}
网友评论