3
I’m having difficulties, because in a file manipulation exercise in Java, the teacher asked us to create a program that takes the name and note 1 and note 2 of two proofs and store in a txt file as follows: name;Nota1;nota2 only that later in another exercise he asks to read from the file the data and calculate the media of the notes saving again the data in another file in the following form name;Nota1;nota2;media, as I do this reading and save the data in variable String,float, float again ???
public class LeitorComun extends Leitor {
private String nome;
private double n1,n2,media;
String linha;
public LeitorComun(FileInputStream arquivo) {
super(arquivo);
}
@Override
public void ler() throws IOException{
InputStreamReader isr = new InputStreamReader(this.arquivo);
BufferedReader br = new BufferedReader(isr);
do{
this.linha = br.readLine();
if(this.linha != null){
String [] palavras = this.linha.split(";");
System.out.println("nova linha ------------------------------------");
for(int i =0; i<palavras.length;i++){
System.out.println("palavra lida: "+ palavras[i]);
}
}
}while(this.linha != null);
}
}
What have you tried to do? Add to question.
– user28595
This 'file' you want to read is a . txt? was very confusing your question. Maybe to answer your question, you can use a String[3] and convert notes 1 and 2 with parseint.
– Raphão Torres
It is for in the second problem I have to read from the.txt file I created, it has the name and the notes, Ex: Marco;11.5;22.3, as I will read the name and the notes and put in the variables name,Nota1,nota2, being that when reading by Inputstreamreader and Bufferedreader they read the whole line, how I will separate the data ???
– Marco Antonio Gomes