posts - 59, comments - 244, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

java获取剪贴板中的链接

Posted on 2012-08-30 11:59 penngo 阅读(578) 评论(0)  编辑  收藏 所属分类: Java
Clipboard clip = Toolkit.getDefaultToolkit()
                        .getSystemClipboard();
                Transferable trans = clip.getContents(this);
                DataFlavor[] flavors = trans.getTransferDataFlavors();
                try {
                    for (DataFlavor cur : flavors) {
                        if (cur.isMimeTypeEqual("text/plain")) {
                            Reader r = (Reader) trans.getTransferData(cur);
                            BufferedReader br = new BufferedReader(r);
                            String src = br.readLine();
                            if (src.startsWith("http://")
                                    || src.startsWith("https://")) {
                                map.put("url", src);
                            }
                            br.close();
                            break;
                        }
                    }
                } catch (Exception e) {
                    System.out.println("===newDownloadInit:" + e.getMessage());
                }

只有注册用户登录后才能发表评论。


网站导航: