-
renameTo() works properly on Unix but not in Windows
I'm trying to simply move (File.renameTo()) a file from a directory to another
and it works well on Unix but not in Windows.
I've read other bug requests related to that tried to follow all recomendations
but nothing works !
I'm reading an existing file using a BufferedReader and closing it before
the
move operation (as I'm closing it on a "finally" statement I'm really sure
that
the close operation was done !). But the answer is allways "false" when I
run
the application on Windows.
I also tried to delete the file (file.delete()) and it ocurrs the same way.
Folowing, the code:
//Move file to "Done" directory
File inFile = new File("c:\\Example\\example.txt"); //existing
File
File outFile = ("c:\\Example\\Done\\example.txt"); //non existing
File
useFile(); //Function that reads the file
//and closes the BufferedReader using
// in the "finally" statement
if (inFile.renameTo(out))
System.out.println("Move operation successfull !");
else
System.out.println("Move operation failed !");
-
Re: renameTo() works properly on Unix but not in Windows
hi patrick,
the file seperator in the unix & windows is different. i.e.,
d:\\abc in windows
d://abc in unix.
to overcome this dependancy use java.io.File.separator
regards...
"Patrick" <ptckweiss@freesurf.ch> wrote:
>
>I'm trying to simply move (File.renameTo()) a file from a directory to another
>and it works well on Unix but not in Windows.
>I've read other bug requests related to that tried to follow all recomendations
>but nothing works !
>I'm reading an existing file using a BufferedReader and closing it before
>the
>move operation (as I'm closing it on a "finally" statement I'm really sure
>that
>the close operation was done !). But the answer is allways "false" when
I
>run
>the application on Windows.
>I also tried to delete the file (file.delete()) and it ocurrs the same way.
>Folowing, the code:
>
> //Move file to "Done" directory
> File inFile = new File("c:\\Example\\example.txt"); //existing
>File
> File outFile = ("c:\\Example\\Done\\example.txt"); //non existing
>File
>
>
> useFile(); //Function that reads the file
> //and closes the BufferedReader using
> // in the "finally" statement
>
> if (inFile.renameTo(out))
> System.out.println("Move operation successfull !");
> else
> System.out.println("Move operation failed !");
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks