• Post Reply Bookmark Topic Watch Topic
  • New Topic

File.renameTo() Failing On Solaris  RSS feed

 
Sanket Meghani
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to move a file from one directory to other directory. Source and destination directories are completely different. For example source dir = /data/logs and destination directory=/export/home/archived. While trying to move file from source directory to destination directory using File.renameTo(), it always fails. The same code is working on Windows machine.

Source code I am using is:



Here success is always false. I am executing this code on Solaris 9 and Java 1.5.0_16. This code runs successfully (success is true) on Windows machine.

Any thoughts on the reason for this behavior?

Thank you,
Sanket
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual cause for renameTo or delete not working is that the file is open by your program or some other process.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you have no rights to write to the folder, which is quite regular for Unix systems.
 
Sanket Meghani
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The same piece of code works if I change source directory and destination directory to partially same path. For example the program works for srcFile = /data/logs/log.txt and destinationFile=/data/archive/log.txt. The problem occurs only if the destination directory do not have any overlapping path with source directory. For example program does not work for srcFile=/data/logs/log.txt and destinationFile=/export/home/log.txt
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sanket Meghani ,

Well i also faced the same problem.

to resolve i follow this algo-
1. copy the from src to dest directory.
2. Delete the file from src dir.

For copying i use FileChannel.
Here is the code-




for delete--



Check it out. It may solve your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!