import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class writeZip {
?/**
? * 取服务器端时间
? *
? * @return
? */
?public static String creatertimes() {
??Date date = new Date();
??SimpleDateFormat sdfs = new SimpleDateFormat("yyyyMMddHHmmss");
??String s = sdfs.format(date);
??return s;
?}
?
?public static void main(String[] argv) throws Exception {
??Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
??//打印系统剪切板里的内容
??System.out.println(getClipboardText(sysc));
??String url = getClipboardText(sysc);
??//往系统剪切板写 参数为时间
??setClipboardText(sysc,url+creatertimes());
??//打印加上日期以后的
??System.out.println(getClipboardText(sysc));
??
?}
?//获取剪切板内容
?protected static String getClipboardText(Clipboard clip) throws Exception{
??// 获取剪切板中的内容
??Transferable clipT = clip.getContents(null);
??if (clipT != null) {
??// 检查内容是否是文本类型
??if (clipT.isDataFlavorSupported(DataFlavor.stringFlavor))
?
???return (String)clipT.getTransferData(DataFlavor.stringFlavor);
??}
??return null;
??}
?
?//添加剪切板内容
?protected static void setClipboardText(Clipboard clip, String write) {
??Transferable tText = new StringSelection(write);
??clip.setContents(tText, null);
??
?}
}