2017-04-21 49 views

回答

6

此代碼段是在Java訪問和打印剪貼板數據:

import java.awt.datatransfer.*; 
    import java.awt.*; 
    /** 
    * Demo to access System Clipboard 
    */ 
    public class SystemClipboardAccess { 

     public static void main(String args[])throws Exception 
     { 

      // Create a Clipboard object using getSystemClipboard() method 
      Clipboard c=Toolkit.getDefaultToolkit().getSystemClipboard(); 

      // Get data stored in the clipboard that is in the form of a string (text) 
      System.out.println(c.getData(DataFlavor.stringFlavor)); 
     } 
    } 
2
import java.awt.HeadlessException; 
import java.awt.Toolkit; 
import java.awt.datatransfer.DataFlavor; 
import java.awt.datatransfer.UnsupportedFlavorException; 
import java.io.IOException; 

public static String readClipboard(){ 
    return (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); 
}