Here you can find the source of getFilenameFromClipboard(Clipboard clip)
Parameter | Description |
---|---|
clip | a parameter |
public static String getFilenameFromClipboard(Clipboard clip)
//package com.java2s; /*/*w w w . j av a 2s. c o m*/ * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.io.File; import java.util.List; public class Main { /** * Returns filename if clipboard contains it and the file exists, otherwise * returns null * * @param clip */ public static String getFilenameFromClipboard(Clipboard clip) { if (clip.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) { // check that file exists and is it image try { List files = (List) clip .getData(DataFlavor.javaFileListFlavor); if (files.size() == 1) { File file = (File) files.get(0); if (file.exists()) return file.getAbsolutePath(); } } catch (Exception e) { e.printStackTrace(); } } if (clip.isDataFlavorAvailable(DataFlavor.stringFlavor)) { try { String path = (String) clip .getData(DataFlavor.stringFlavor); if (path.length() < 512) { File file = new File(path); if (file.exists()) { return file.getAbsolutePath(); } } } catch (Exception e) { e.printStackTrace(); } } return null; } }