JAVAFX文件保存代码参考
2021/12/12 1:19:46
本文主要是介绍JAVAFX文件保存代码参考,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package com.task; import java.io.File; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import java.util.Iterator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; public class FileCopyFx extends Application { @Override public void start(Stage primaryStage) { TextField tf = new TextField(); tf.setPrefWidth(500); Button btn = new Button("复制文件"); HBox hb = new HBox(); hb.getChildren().addAll(tf, btn); Scene scene = new Scene(hb, 1000, 500); primaryStage.setScene(scene); primaryStage.show(); btn.setOnAction((e) -> { FileChooser fc = new FileChooser(); List<File> files = fc.showOpenMultipleDialog(primaryStage); Iterator<File> it = files.iterator(); DirectoryStream<Path> ds = null; Path path; File file; Path _path; File _file; try { ds = Files.newDirectoryStream(Paths.get("d:\\dir")); Iterator<Path> _it = ds.iterator(); while (it.hasNext() && _it.hasNext()) { file = it.next(); path = file.toPath(); _path = _it.next(); _file = _path.toFile(); System.out.println(file.getPath()); System.out.println(_file.getPath()); Files.copy(path, _path, REPLACE_EXISTING); file = new File(_path.getParent().toFile().getPath(), file.getName()); _file.renameTo(file); Files.move(file.toPath(), Paths.get(tf.getText() + File.separator + file.getName()), REPLACE_EXISTING); } } catch (IOException ex) { ex.printStackTrace(); } }); } public static void main(String[] args) throws IOException { launch(args); } }
这篇关于JAVAFX文件保存代码参考的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?