简体   繁体   English

如何覆盖 JXBrowser 默认下载文件路径?

[英]How to override JXBrowser default downloads file path?

I am trying to figure out that any property exists at JX Browser level to provide default downloads path location for files/images.我试图找出 JX 浏览器级别存在的任何属性,以提供文件/图像的默认下载路径位置。 I see that we have setPopupHandler and setDownloadHandler in Java side but just wanted to know any property exists at JX Browser level so that end user can have a choice to change at anytime like google chrome Settings -> Advanced -> Downloads -> Location我看到我们在 Java 端有setPopupHandlersetDownloadHandler但只是想知道 JX 浏览器级别存在任何属性,以便最终用户可以选择随时更改,例如 google chrome 设置 -> 高级 -> 下载 -> 位置

To override the default downloads file path, you'll need to get the filename of it, then create a new file with your custom file path + filename.要覆盖默认下载文件路径,您需要获取它的文件名,然后使用自定义文件路径 + 文件名创建一个新文件。 In the final, set the default destination file to that file.最后,将默认目标文件设置为该文件。 Like this.像这样。

            browser.setDownloadHandler(new DownloadHandler() {
                public boolean allowDownload(DownloadItem download) {
                    String fileName = FilenameUtils.getName(download.getDestinationFile().getAbsolutePath());
                    //String ext = "." + FilenameUtils.getExtension(download.getDestinationFile().getAbsolutePath());
                    String destination = "C:\\yourPath\\downloadLocation\\";
                    File file = new File(destination + fileName);
                    download.setDestinationFile(file);
                    
                    download.addDownloadListener(new DownloadListener() {
                        public void onDownloadUpdated(DownloadEvent event) {
                            DownloadItem download = event.getDownloadItem();

                            if (download.isCompleted()) {
                                System.out.println("Download is completed!");
                            }
                        }
                    });
                    System.out.println("Dest file: " + download.getDestinationFile().getAbsolutePath());
                    return true;
                }
            });

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

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