How do I properly handle file copy/cut & paste in javafx?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 02:27:18

问题


I'm working on a program in which I want to add the possibility of copy-pasting (or cut-pasting) files. I could create it so it only works within the program, but it would be nicer if I could use the system-wide clipboard. That has one huge problem though: when pasting I don't know if files are copied or cut from the system explorer, I only get the file locations.

I am using Java and the javafx clipboard. Some sample code:

Clipboard clipboard = Clipboard.getSystemClipboard();
List<File> files = clipboard.getFiles();

// destDir is a File, the target directory.
for (File oldFile : files) {
    if (oldFile.isDirectory()) {
        FileUtils.copyDirectoryToDirectory(oldFile, destDir);
    } else {
        FileUtils.copyFileToDirectory(oldFile, destDir);
    }
}

Here I simply copy the files, but how do I for example know when to use FileUtils.copyDirectoryToDirectory and when to use FileUtils.moveDirectoryToDirectory (aka copy or cut)?

Thanks,
Luca


回答1:


Turns out, as pointed out by Fildor , that this is only possible when using drag and drop with the Dragboard. The Clipboard does not have such functionality.



来源:https://stackoverflow.com/questions/34133307/how-do-i-properly-handle-file-copy-cut-paste-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!