This is the first time that I post in this place, I am a beginner in this of java and I had a small inconvenience when wanting to make a file modification.
Well, what happens is that I want to make a file modification sending a window's labels as a parameter, search through the code that enters a label, when I find it I want it to modify, delete and rename the temporary file , which does not happen and I do not know why, I can not find the reason why he prints me that he did not change, if he creates the storm and everything but does not erase the previous one and renames the storm.
public void modificar(int codE, String nomE, int cantE,double precE) throws IOException {
ficheroA = new File("C:\Users\GRIS\Desktop\archivosproyecto\Articulos");
File ficheroAtemp = new File("C:\Users\GRIS\Desktop\archivosproyecto\Atemporal");
int codigo = 0;
int cantidad= 0;
double precio=0;
String nombre = " ";
int band = 0;
boolean existe= false;
flujolee = new FileInputStream(ficheroA);
leer = new DataInputStream(flujolee);
flujoescribe = new FileOutputStream(ficheroAtemp, true);
escribir = new DataOutputStream(flujoescribe);
try {
while (true) {
codigo = leer.readInt();
nombre = leer.readUTF();
cantidad = leer.readInt();
precio = leer.readDouble();
if (codE == codigo) {
band = 1;
existe=true;
}
escribir.writeInt(codE);
escribir.writeUTF(nomE);
escribir.writeInt(cantE);
escribir.writeDouble(precE);
}
} catch (IOException error) {
}
try {
leer.close();
escribir.close();
if (existe = true) {
if (ficheroA.delete()) {
if (ficheroAtemp.renameTo(ficheroA)) {
System.out.println("modificado");
}
else {
System.out.println("no se pudo modificar el archivo");
}
}
}
} catch (IOException e) {
System.out.println("ERROR");
}
}