java實現複製內容到剪貼簿
阿新 • • 發佈:2018-12-31
package com.yang.clipboard;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
public class ClipBoardUtil {
public static void main(String[] args) {
// TODO Auto-generated method stub
setSysClipboardText("複製的內容" );
}
/**
* 將字串複製到剪下板。
*/
public static void setSysClipboardText(String writeMe) {
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText = new StringSelection(writeMe);
clip.setContents(tText, null);
}
}