FileChooser fc = new FileChooser();
fc.setTitle("请选择文件保存位置");
fc.setInitialDirectory($原始文件位置$); //桌面位置 private final static File homeDirectory = FileSystemView.getFileSystemView().getHomeDirectory();
fc.setInitialFileName($文件名$);标签:样例,保存,ButtonType,alert,fc,FileChooser,new,Alert From: https://www.cnblogs.com/PJRAWA/p/16812445.html
fc.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("XLSX", "*.xlsx")); //添加文件类型筛选
File exportFile = fc.showSaveDialog(null); //设置弹出窗口所属父窗口,返回用户选择的文件路径
if (null != exportFile) {
try {
FileUtils.copyFileToDirectory(new File(SCD_URL), new File(exportFile.getParent())); //只需要获得文件保存位置的父路径就行
Alert alert = new Alert(Alert.AlertType.NONE, "下载成功", new ButtonType[]{ButtonType.CLOSE});
alert.setTitle("确认");
alert.show();
} catch (IOException e) {
Alert alert = new Alert(Alert.AlertType.NONE, "下载失败,请联系管理员", new ButtonType[]{ButtonType.CLOSE});
alert.setTitle("确认");
alert.show();
e.printStackTrace();
}
}