繁体   English   中英

如何将两个单独的文件复制到 Java 中的两个单独位置?

[英]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();
                                    }
                                };
                        }

                    }

                }
            }
        });

这就是我到目前为止所得到的,它所做的是将我选择的第二个文件放入第一个目录(path1 或 images/small/),而我想要发生的是我选择的第一个文件进入 path1我选择的第二个文件进入 path2。

所以我想通了,我有两个单独的文件选择器,一个用于单个文件,一个用于多个文件,因此它并没有像我想象的那样填充列表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM