2

I'm trying to rename a file which I have access by RandomAccessFile. When I do all changes I want in the temporary archive, I close the two RAF. But when I try to move the file, to rename(replacing) it says that my archives are been used by other process.

When the application is running I can't do nothing with the archive manually, but when the application closes, I can do anything that I want.

newraf.close();
raf.close();

File temp = new File(userHome+"\\orig.temp");
File orig = new File(userHome+"\\orig.ejb");
Files.move(temp.toPath(), orig.toPath(), REPLACE_EXISTING );

I tried using other manner, but didn't worked:

newraf.close();
raf.close();
File temp = new File(userHome+"\\orig.temp");
File orig = new File(userHome+"\\orig.ejb");
temp.renameTo(orig);

I saw this, but didn't help too much.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Francisco Cabral
  • 856
  • 11
  • 21
  • what is the OS platform? – Mehul Rathod Aug 05 '13 at 03:42
  • @MehulRathod Windows 8 Pro – Francisco Cabral Aug 05 '13 at 03:46
  • checkout my previous answer http://stackoverflow.com/questions/17979638/cant-delete-file-after-it-gets-written/17979764#17979764 i think you are having the same issue – Mehul Rathod Aug 05 '13 at 03:49
  • But the problem is that I can do anything with the archive when de application is closed. If the antivirus is scanning I couldn't do anything. And I can also write in the archive, I only can't close in runtime. – Francisco Cabral Aug 05 '13 at 04:01
  • So have you tried to find out what has the file(s) open? Like the linked Answer suggests? – Stephen C Aug 05 '13 at 04:04
  • The only thing what uses this archive is this aplication. I tried to change the names, I got same error. I saw [this](http://stackoverflow.com/questions/1213374/randomaccessfiles-dont-close-until-application-exit?rq=1) topic, it's kind of same problem. I'm trying to put in pratice. – Francisco Cabral Aug 05 '13 at 04:15
  • See this question: http://stackoverflow.com/questions/25238110/cannot-delete-file-even-after-randomaccessfile-is-closed – ZhekaKozlov Aug 11 '14 at 15:20

0 Answers0