3 Replies Latest reply: Aug 16, 2007 2:54 PM by 807605 RSS

    Wait until text-file is REALLY close

    807605
      How can I protect file-write if power is shutdown imediately?

      I write tmp file and I need read data from this file after power shutdown(or hard reset), but file is sometimes corrupted.
      FileWriter ff = new FileWriter(lastFILE,false); //new file
      f.write("<kredit><" + kredit + ">");
      f.write("<pot><"    + pot    + ">");
      f.write("<bonus><"  + bonus  + ">");
      f.close();
      Error is sometimes occuring when I make test:
      1)I write data to file
      2) wait aprox. 1 sec (in Java there is 1 second after close function)
      3) turn off PC, switch-off (or hard reset)
      4) turn on PC and file is corrupted


      I use Windows XP(ntfs) on Compat Flash Card. I turned off write caching in Windows for HDD but problem is still during.

      I think error is in Operation System because there is write caching on HDD and that's why I am looking for some function which will be wait if file is really close.


      Any Ideas?
      Thanks.