JavaFX problem with JfileChooser

0

Hello colleagues, you will see I have a question, I'm doing a program which I need to attach files to show me in a textarea and then when I click on the save button, ask me the route to which I want to keep these attachments here I leave the parts of my code to see if you can lend me a hand many thanks in advance.

ArrayList<String>nombres = new ArrayList<String>();
ArrayList<String>nombres1 = new ArrayList<String>();
ArrayList<String>nombres2 = new ArrayList<String>();

@FXML private void adSegMercancia(ActionEvent event){
	FileChooser fileChooser = new FileChooser();
	File selectedFile = fileChooser.showOpenDialog(null);
 
	if (selectedFile != null) {
		nombres.add(selectedFile.getName()+"\n");
		//DocMostrar.setText("File selected: " + selectedFile.getName());
		for(int a = 0; a<nombres.size();a++){
			DocMostrar.setText(selectedFile.getName()+"\n");
		}
	}
 
 
}
@FXML private void adFichaTecnica(ActionEvent evetn){
	FileChooser fileChooser = new FileChooser();
	File selectedFile = fileChooser.showOpenDialog(null);
 
	if (selectedFile != null) {
		nombres1.add(selectedFile.getName()+"\n");
		for(int a = 0; a<nombres1.size();a++){
			DocMostrar1.setText(selectedFile.getName()+"\n");
		}
	}
 
}
@FXML private void adTarjTransporte(ActionEvent evetn){
	FileChooser fileChooser = new FileChooser();
	File selectedFile = fileChooser.showOpenDialog(null);
 
	if (selectedFile != null) {
		nombres2.add(selectedFile.getName()+"\n");
		for(int a = 0; a<nombres2.size();a++){
			DocMostrar2.setText(selectedFile.getName()+"\n");
		}
	}
 
}

@FXML private void Save(ActionEvent event) {
proveedores Proveedores = new proveedores();
Proveedores.nombrep.set(nombreP.getText());
Proveedores.cifp.set(cifP.getText());
Proveedores.direccionp.set(direccionP.getText());
Proveedores.numerop.set(numeroP.getText());
Proveedores.poblacionp.set(poblacionP.getText());
Proveedores.provinciap.set(provinciaP.getText());
Proveedores.paisp.set(paisP.getText());
Proveedores.cpp.set(cpP.getText());
Proveedores.telefonop.set(telefonoP.getText());
 
proveedores2.add(Proveedores);
 
try
{
    fichero2 = new FileWriter(CsvFile2,true);
    Pw = new PrintWriter(fichero2);
    String aux = Proveedores.getNombrep()+ ";" + Proveedores.getTelefonop() + ";" + Proveedores.getCifp()+";"+Proveedores.getDireccionp()+";"+Proveedores.getNumerop()
    +";"+Proveedores.getPaisp()+";"+Proveedores.getPoblacionp()+";"+Proveedores.getProvinciap()+";"+Proveedores.getCpp();
        Pw.println(aux);
 
} catch (Exception e) {
    e.printStackTrace();
} finally {
   try {
   // Nuevamente aprovechamos el finally para 
   // asegurarnos que se cierra el fichero.
   if (null != fichero2)
      fichero2.close();
   } catch (Exception e2) {
      e2.printStackTrace();
   }
}
    
asked by Nikolai Ivanov 23.01.2018 в 17:27
source

0 answers