簡體   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