I use this code in a Java Swing application to copy files to the clipboard:
final List<File> files = new ArrayList<File>();
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new Transferable() {
@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 {
return files;
}
}, null
);
This works because I can go to Windows Explorer and Ctrl + V, and the files will appear (I hope it works on other OSs, although not tested). I would like to implement cut , but I do not know how to tell the system what this action is, or, alternatively, how to get feedback for each successfully copied file so that I can remove it from the original location manually.
If this is not impossible, any suggestions on how I should deal with this? I would like to be able to cut and paste into the application too (separately for file sharing with the OS browser).
source
share