mountainsListView.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
if (mouseEvent.getClickCount() == 2) {
FileChooser fileChooser = new FileChooser();
Window stage = null;
fileChooser.showOpenDialog(stage);
List<File> list = fileChooser.showOpenMultipleDialog(stage);
String path1 = "images/small/";
String path2 = "images/large/";
if (list != null) {
for (int i = 0; i < list.size(); i++) {
File file = list.get(i);
try {
if (i == 0) {
fileChooser.setTitle("Add Small Mountain File");
Files.copy(file.toPath(), (new File(path1 + file.getName())).toPath(),
StandardCopyOption.REPLACE_EXISTING);
} else {
fileChooser.setTitle("Add Large Mountain File");
Files.copy(file.toPath(), (new File(path2 + file.getName())).toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}
}
}
}
});
这就是我到目前为止所得到的,它所做的就是将我选择的第二个文件放入第一个目录(path1或images/small/),而我想要发生的是我选择的第一个文件进入path1,我选择的第二个文件进入path2。
最佳答案
所以我发现,我有两个单独的文件选择器,一个用于单个文件,一个用于多个文件,因此它没有按照我想象的方式填充列表。
关于java - 如何在 Java 中将两个单独的文件复制到两个单独的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61200073/