I started working a little bit at a company that programs the MiFire cards and I'm in the experimental phase. Meanwhile the engineer told me to do a job.
First step:
I have to enter two numeric values and get the result of the sum; Save in a sequential file the parcels and the result of the sum; Each saved file line "f1" contains 3 information:
linha1<- p1, p2, soma
linha2<- p1, p2, soma
Second stage:
Read the saved file and show the parcels with element of a multiplication and get the result. Record in a txt file "f2" the elements and the product in each line.
I'm trying to do but I just can not, could anyone 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){
}