【问题标题】:How do I copy two separate files into two separate locations in Java?如何将两个单独的文件复制到 Java 中的两个单独位置?
【发布时间】:2020-04-14 03:05:30
【问题描述】:
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 file-io copy


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      相关资源
      最近更新 更多