问题描述
我正在开发一个程序,我希望在其中添加复制粘贴(或剪切粘贴)文件的可能性。我可以创建它,所以它只能在程序中工作,但如果我可以使用系统范围的剪贴板会更好。这有一个很大的问题:粘贴时我不知道是否从系统资源管理器复制或剪切文件,我只获取文件位置。
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.
我正在使用Java和javafx剪贴板。一些示例代码:
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);
}
}
这里我只是复制文件,但我该怎么做例如,知道何时使用 FileUtils.copyDirectoryToDirectory
以及何时使用 FileUtils.moveDirectoryToDirectory
(又名复制或剪切)?
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
推荐答案
转身out,,只有在使用Dragboard拖放时才可以这样做。剪贴板没有这样的功能。
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.
这篇关于如何正确处理文件复制/剪切&粘贴在javafx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!