3
I just started working at a company that programs the Mifire cards and I’m in the experimental phase. Meanwhile the engineer ordered me to do a job.
First stage:
I have to enter two numerical values and get the result of the sum; Store the plots and the sum result in a sequential file; Each file line saved "F1" contains 3 information:
linha1<- p1, p2, soma
linha2<- p1, p2, soma
Second stage:
Read the saved file and show the plots with a multiplication element and get the result. Save elements and product in each line to a txt file "F2".
I’m trying to do it but only I’m not getting it, someone could help me??
int n1 = Integer.parseInt(txtN1.getText());
int n2 = Integer.parseInt(txtN2.getText());
int soma = n1 + n2;
//int mult = n1 * n2;
txtR.setText(Integer.toString(soma));
//txtRM.setText(Integer.toString(mult));
String linhat = "";
//Ler e gravar no primeiro arquivo
File arq = new File("arquivo.txt");
try{
arq.createNewFile();
FileReader ler = new FileReader(arq);
FileWriter fileWriter = new FileWriter(arq);
BufferedWriter escrever = new BufferedWriter(fileWriter);
linhat = Integer.toString(n1)+ ";";
escrever.write(linhat);
linhat = Integer.toString(n2)+";";
escrever.write(linhat);
linhat = Integer.toString(soma) ;
escrever.write(linhat);
PrintWriter gravarArq = new PrintWriter(arq);
gravarArq.print(linhat);
escrever.close();
fileWriter.close();
BufferedReader lerb = new BufferedReader(ler);
String linha = lerb.readLine();
while(linha !=null){
System.out.println(linha);
linha = lerb.readLine();
//ler o ficheiro
File file = new File("arquivo.txt");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
// gravar o ficheiro "f2"
File file = new File("arquivo2.txt");
FileWriter fw = new FileWrite(file);
BufferedReader bw = new BufferedReader(fw);
String s ="",
bw.newLine;
bw.write(s);
bw.flush();
/* Scanner in = new Scanner(new FileReader("arquivo.txt"));
while(in.hasNextLine()){
String line = scanner.nexteLine();
System.out.println(line);
*/
}
}catch (IOException ex){
}