How can I copy a file and paste it to the clipboard using Java?
<p>How can I copy a file and paste it to the clipboard using Java? My program can copy but it cannot paste. It gives</p>

<blockquote>
  <p>Exception in thread "main" java.lang.ClassCastException:<br>
  java.util.Arrays$ArrayList cannot be cast to java.io.File</p>
</blockquote>

<p>My code:</p>

<pre><code>class FileTransferable implements Transferable {
    private final File file;

    public FileTransferable(File file) {
        this.file = file;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[] { DataFlavor.javaFileListFlavor };
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return DataFlavor.javaFileListFlavor.equals(flavor);
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        final ArrayList&lt;File&gt; files = new ArrayList&lt;File&gt;();
        files.add(file);
        return files;
    }
}
</code></pre>
