[英]How do I copy two separate files into two separate locations in Java?
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();
}
};
}
}
}
}
});
This is what I've got so far and what its doing is taking the second file I pick and putting it into the first directory (path1 or images/small/) when what I want to happen is the first file I pick goes into path1 and the second file I pick goes into path2.这就是我到目前为止所得到的,它所做的是将我选择的第二个文件放入第一个目录(path1 或 images/small/),而我想要发生的是我选择的第一个文件进入 path1我选择的第二个文件进入 path2。
So I figured it out, I had two separate filechoosers, one for single files and one for multiple so it was not filling the list the way I thought it was.所以我想通了,我有两个单独的文件选择器,一个用于单个文件,一个用于多个文件,因此它并没有像我想象的那样填充列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.