aspose file tools
The moose likes Java in General and the fly likes File.renameTo() Failing On Solaris Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File.renameTo() Failing On Solaris" Watch "File.renameTo() Failing On Solaris" New topic

File.renameTo() Failing On Solaris

Sanket Meghani

Joined: Jan 15, 2007
Posts: 14

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,
Joe Ess

Joined: Oct 29, 2001
Posts: 9102

The usual cause for renameTo or delete not working is that the file is open by your program or some other process.

[How To Ask Questions On JavaRanch]
Rob Spoor

Joined: Oct 27, 2005
Posts: 19992

Or if you have no rights to write to the folder, which is quite regular for Unix systems.

How To Ask Questions How To Answer Questions
Sanket Meghani

Joined: Jan 15, 2007
Posts: 14

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

Joined: Sep 04, 2008
Posts: 122
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.
subject: File.renameTo() Failing On Solaris