PROBLEM SAVING A .TXT FILE

I run this piece of code inside a bigger loop, these lines save a string in a .txt file called "kinectDEM.tmp", before to do that the old file is renamed in "kinectDEM1.txt" and the new one ("kinectDEM.tmp") is renamed in"kinectDEM0.txt". It works fine but sometimes it get stuck and the "kinectDEM1.txt" disappear, blocking the loop. How can I fix it?

 if (millis() > precedente + savingtimestep) {
    txt[0] = "ncols         600\nnrows         480\nxllcorner     0\nyllcorner     0\ncellsize      1\nNODATA_value  10\n" +kinectDEM;
    saveStrings("kinectDEM0.tmp", txt);
    precedente = millis();
    //  delete the old .txt file, from kinectDEM1 to kinectDEMtrash
    File f = new File(sketchPath("kinectDEM1.txt"));
    boolean success = f.delete();

    //  rename the old .txt file, from kinectDEM0 to kinectDEM1
    File oldName1 = new File(sketchPath("kinectDEM0.txt"));
    File newName1 = new File(sketchPath("kinectDEM1.txt"));
    oldName1.renameTo(newName1);

    //  rename kinectDEM0.tmp file to kinectDEM0.txt
    File oldName2 = new File(sketchPath("kinectDEM0.tmp"));
    File newName2 = new File(sketchPath("kinectDEM0.txt"));
    oldName2.renameTo(newName2);
  }

Answers

Sign In or Register to comment.