Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

File.renameTo() Failing On Solaris  RSS feed

 
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
 
Bartender
Posts: 9508
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.
 
Sheriff
Posts: 21421
94
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
 
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!