I'm trying to read a file with CSV format which has movie information through a Filereader, add all the elements in a list and then display them in a Tableview in JavaFX. The problem is that I do not execute my method.
'/ * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. * / package act8;
import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable;
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.stage.FileChooser; import javafx.stage.Stage; import javax.swing.JOptionPane;
/ ** * * @author Anton * / public class FXMLDocumentController implements Initializable { Scene scene; Stage window; Scanner sc = new Scanner (System.in); FileChooser fs;
@FXML
private TextField txtdatosd;
@FXML
private TextField txtdatosr;
@FXML
private Button btnAbrirD;
@FXML
private Button btnAbrirR;
@FXML
private Button btncargard;
@FXML
private TableView tbldisponibles;
public void abrirD() throws IOException{
File f=null;
f=fs.showOpenDialog(window);
if(f != null){
txtdatosd.setText(f.getAbsolutePath());
}
}
public void leerArchivoCSVd() throws FileNotFoundException, IOException{
String csvFile = (txtdatosd.getText());
BufferedReader br = null;
String line="";
// Define separator ","
String cvsSplitBy=",";
try {
br = new BufferedReader (new FileReader (csvFile));
while ((line = br.readLine ())! = null) {
String [] data = line.split (cvsSplitBy);
// Print data.
System.out.println (data [0] + "," + data [1] + "," + data [2] + "," + data [3] + "," + data [4]);
}
} catch (FileNotFoundException e) {
e.printStackTrace ();
} catch (IOException e) {
e.printStackTrace ();
} finally {
if (br! = null) {
try {
br.close ();
} catch (IOException e) {
e.printStackTrace ();
}
}
}
}
public void escucha(){
btnAbrirD.setOnAction(evt ->{try {
abrirD();
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
escucha();
}
} '