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 !");
[1131 byte] By [
Patrick] at [2007-11-9 22:29:36]

# 1 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 !");
>
sachin at 2007-11-11 23:03:07 >
