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
JavaRanch » Java Forums » Java » Java in General
Bookmark "File.renameTo() Failing On Solaris" Watch "File.renameTo() Failing On Solaris" New topic
Author

File.renameTo() Failing On Solaris

Sanket Meghani
Greenhorn

Joined: Jan 15, 2007
Posts: 14
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

Joined: Oct 29, 2001
Posts: 8908
    
    8

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sanket Meghani
Greenhorn

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File.renameTo() Failing On Solaris