Atitit 剪贴板数据类型 DataFlavor 目录 1. HtmlFlavor 1 1.1. allHtmlFlavor 1 1.2. selectionHtmlFlavor 1 1.3. fr

Atitit 剪贴板数据类型 DataFlavor

目录

1. HtmlFlavor 1

1.1. allHtmlFlavor 1

1.2. selectionHtmlFlavor 1

1.3. fragmentHtmlFlavor 2

2. imageFlavor 2

2.1. javaFileListFlavor 3

2.2. plainTextFlavor 3

2.3. stringFlavor 5

3. Code 5

 

 

  1. HtmlFlavor
    1. allHtmlFlavor

   representationClass = String

     *     mimeType           = "text/html"

 

    1. selectionHtmlFlavor

 * <pre>

     *     representationClass = String

     *     mimeType           = "text/html"

     * </pre>

     */

    public static DataFlavor selectionHtmlFlavor

    1. fragmentHtmlFlavor

 representationClass = String

     *     mimeType           = "text/html"

     * </pre>

     */

public static DataFlavor fragmentHtmlFlavor

 

  1. imageFlavor

* <pre>

     *     representationClass = java.awt.Image

     *     mimeType            = "image/x-java-image"

     * </pre>

     */

    public static final DataFlavor imageFlavor

 

 

 

    public static final String javaSerializedObjectMimeType = "application/x-java-serialized-object";

    1. javaFileListFlavor 

    /**

     * To transfer a list of files to/from Java (and the underlying

     * platform) a <code>DataFlavor</code> of this type/subtype and

     * representation class of <code>java.util.List</code> is used.

     * Each element of the list is required/guaranteed to be of type

     * <code>java.io.File</code>.

     */

    public static final DataFlavor javaFileListFlavor = createConstant("application/x-java-file-list;class=java.util.List", null);

 

    1. plainTextFlavor 

 

  * The <code>DataFlavor</code> representing plain text with Unicode

     * encoding, where:

     * <pre>

     *     representationClass = InputStream

     *     mimeType            = "text/plain; charset=unicode"

     * </pre>

     * This <code>DataFlavor</code> has been <b>deprecated</b> because

     * (1) Its representation is an InputStream, an 8-bit based representation,

     * while Unicode is a 16-bit character set; and (2) The charset "unicode"

     * is not well-defined. "unicode" implies a particular platform's

     * implementation of Unicode, not a cross-platform implementation.

     *

     * @deprecated as of 1.3. Use <code>DataFlavor.getReaderForText(Transferable)</code>

     *             instead of <code>Transferable.getTransferData(DataFlavor.plainTextFlavor)</code>.

     */

    @Deprecated

    public static final DataFlavor plainTextFlavor = createConstant("text/plain; charset=unicode; class=java.io.InputStream", "Plain Text");

 

    1. stringFlavor

    * The <code>DataFlavor</code> representing a Java Unicode String class,

     * where:

     * <pre>

     *     representationClass = java.lang.String

     *     mimeType           = "application/x-java-serialized-object"

     * </pre>

     */

    Pu

 

  1. Code

/bookmarksHtmlEverythingIndexPrj/src/agenepkg/clip.java

package agenepkg;

 

import java.awt.Toolkit;

import java.awt.datatransfer.Clipboard;

import java.awt.datatransfer.DataFlavor;

import java.awt.datatransfer.Transferable;

import java.awt.datatransfer.UnsupportedFlavorException;

import java.io.File;

import java.io.IOException;

import java.util.List;

 

@SuppressWarnings("all")

public class clip {

 

public static void main(String[] args) throws UnsupportedFlavorException, IOException {

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

 

Transferable Transferable1_clipboardContent = clipboard.getContents(null);

// 获取文本中的Transferable对象

 

if (Transferable1_clipboardContent == null)

return;

 

if (!Transferable1_clipboardContent.isDataFlavorSupported(DataFlavor.javaFileListFlavor))

return;

 

List<File> list = (List<File>) (Transferable1_clipboardContent.getTransferData(DataFlavor.javaFileListFlavor));

for (File file : list) {

System.out.println(file);

}

 

}

 

}

猜你喜欢

转载自blog.csdn.net/attilax/article/details/91381904