I am having problems with a program, I need the program to process 10 numbers written in txt
down and write me if they are correct or not. The error is as follows:
Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedWriter.ensureOpen (Unknown Source)
at java.io.BufferedWriter.write (Unknown Source)
at java.io.Writer.write (Unknown Source)
at NifCheck.main (NifCheck.java:18)
Here I leave all the classes:
import java.io.*;
public class NifCheck {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("C:\Users\Pablo\Desktop\NIF.txt");
BufferedReader leer = new BufferedReader(fr);
FileWriter fw = new
FileWriter("C:\Users\Pablo\Desktop\NIFCheck.txt");
BufferedWriter escribir = new BufferedWriter(fw);
GetNum numeronif = new GetNum();
calc cogerletra = new calc();
Check checkeo = new Check();
for (int x = 1;x <=10;x++) {
String leidostr = leer.readLine();
int num = numeronif.num(leidostr);
String letra = cogerletra.letra(num);
System.out.println("Llego a escribir");
escribir.write(leidostr + letra);
escribir.newLine();
escribir.close();
}
}
}
public class GetNum {
int num(String x) {
int largo;
largo = x.length();
String num = x.substring(0, (largo-1));
int num2;
num2 = Integer.parseInt(num);
return num2;
}
}
public class calc {
String letra(int x) {
String letras = "TRWAGMYFPDXBNJZSQVHLCKE";
String a = letras.substring(x%23,x%23+1);
return a;
}
}
public class Check {
public String Check(int num, String letra, String letrastr) {
String codfinal = String.valueOf(num) + letra;
if (codfinal.equals(letrastr)) return " Correcto";
else return " Incorrecto";
}
}