Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testerpackage;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.VBox;
- import javafx.stage.FileChooser;
- import javafx.stage.Stage;
- /**
- * Created by Utshaw on 11/30/2016.
- */
- public class Driver6 extends Application {
- @Override
- public void start(Stage primaryStage) {
- Button btnLoad = new Button("Load");
- btnLoad.setOnAction(btnLoadEventListener);
- VBox rootBox = new VBox();
- rootBox.getChildren().add(btnLoad);
- Scene scene = new Scene(rootBox, 300, 300);
- primaryStage.setTitle("java-buddy.blogspot.com");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- EventHandler<ActionEvent> btnLoadEventListener
- = (ActionEvent event) -> {
- FileChooser fileChooser = new FileChooser();
- fileChooser.getExtensionFilters()
- .addAll(
- new FileChooser.ExtensionFilter("TXT files (*.TXT)", "*.TXT"),
- new FileChooser.ExtensionFilter("txt files (*.txt)", "*.txt"));
- File file = fileChooser.showOpenDialog(null);
- if (file != null) {
- try {
- Files.lines(file.toPath()).forEach(System.out::println);
- } catch (IOException ex) {
- Logger.getLogger(Driver6.class.getName())
- .log(Level.SEVERE, null, ex);
- }
- }
- };
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement