How to move files from java?
1 posts in topic
Flat View  Flat View

Posted By:   Manojkumar_Rananaware
Posted On:   Thursday, February 10, 2005 06:31 AM

I want to move a file from one directory to another. I have tried using File.renameTo() function, but that does not work. Copying to destination and deleting from source directory is not what I need, because I need to retain the time-stamps of the file. Is there any way to do it from java?

I am using it for Widows XP.

Re: How to move files from java?

Posted By:   Stephen_Ostermiller  
Posted On:   Monday, February 14, 2005 03:24 AM

renameTo should work unless the directories are on different disks. In that case anything that moves the file is going to have to rewrite it. Unfortunately in Java, there is no way to control the timestamps easily.

There are some non-cross-platform ways of doing this: Either find a command line that will move the file properly and call it via Runtime.exec(), or write some native code.

About | Sitemap | Contact