public void lerFicheiro(){
try {
Scanner scanner = new Scanner(ficheiro);
while(scanner.hasNextLine()){
//quando numero de campos for igual a 4
String designacaoAeronave = scanner.next();
String capacidadeDeposito = scanner.next();
String conteudoAtualDeposito = scanner.next();
String consumo = scanner.next();
System.out.println(designacaoAeronave);
System.out.println(capacidadeDeposito);
System.out.println(conteudoAtualDeposito);
System.out.println(consumo);
System.out.println("----");
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
I have the following file:
UPT100 100 50 5
CPT100 100 11 5 20
PPT100 100 5 5 120
But the first line has 4 variables to save and the 2nd and 3rd line has 5 variables. With the code I did I can only do as it is in the image. That is to say when it has 5 words delimited by a space prints as if it were the designation of the aircraft of the previous.