It happens that I need a combobox to filter the data by branches. If the click on an item shows me in a table the data of such branch. I'm using a text file as a database (so I was asked) I could only make it save and delete ... It would be very helpful if you could help me I'm using a method to save the data in a txt, save everything written in the jtable.
As much as I could get is through this code ...
Scanner entrada = null;
String linea;
int numeroDeLinea = 1;
boolean contiene = false;
String texto = (String) jcomboSucursal.getSelectedItem();
try {
File f = new File("archivo. txt" );
entrada = new Scanner(f);
while (entrada.hasNext()) { //mientras no se llegue al final del fichero
linea = entrada.nextLine();
if (linea.contains(texto)) { //si la línea contiene el texto buscado se muestra por pantalla
System.out.println("Linea " + numeroDeLinea + ": " + linea);
contiene = true;
}
numeroDeLinea++; //se incrementa el contador de líneas
}
if(!contiene){ //si el archivo no contienen el texto se muestra un mensaje indicándolo
System.out.println(texto + " no se ha encontrado en el archivo");
}
} catch (FileNotFoundException e) {
System.out.println(e.toString());
} catch (NullPointerException e) {
System.out.println(e.toString() + "No ha seleccionado ningún archivo");
} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (entrada != null) {
entrada.close();
}
}
Although it only shows me by console and I want to filter the data and show them in my tablet