How to get html based on specified clipboard?

零下一度
Release: 2017-04-28 15:15:04
Original
1864 people have browsed it

Get html from the specified clipboard. This is a little tricky. Let’s take a look at the code.

    /**
     * 从指定的剪切板中获取html
     * @param clipboard
     * @return
     * @throws Exception
     */
    public static String getClipboardHtml(Clipboard clipboard) throws Exception {
        if(clipboard == null){
            clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();//获取系统剪贴板
        }
        // 获取剪切板中的内容
        Transferable clipT = clipboard.getContents(null);
        if (clipT != null) {
            DataFlavor dataFlavor = new DataFlavor("text/html;class=java.lang.String");
            return String.valueOf(clipT.getTransferData(dataFlavor));
        }
        return null;
    }
Copy after login

The above is the detailed content of How to get html based on specified clipboard?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template