aspose file tools*
The moose likes I/O and Streams and the fly likes renameTo() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "renameTo() problem" Watch "renameTo() problem" New topic
Author

renameTo() problem

paolo colombini
Greenhorn

Joined: Jun 09, 2004
Posts: 4
Hallo everybody,
I'm a little bit new to Java and I'a trying to sort out the problem I'am going to show you.

I have this piece of code:

File FileTasso = new File(txtFileNYinTasso.getText().toString());
File NewFileTasso = new File("d:\\paolib\\java\\prove\\rtlny\\beta.txt");

boolean success;
success = FileTasso.renameTo(NewFileTasso);
if (!success) {
jOptionPane1.showMessageDialog(this, "Rename error: " + FileTasso.toString());
}

I copied the instruction from some other code I have found in this forum.

The problem is that it does not work !

txtFileNYinTasso is a JTextField and contains d:\\paolib\\java\\prove\\rtlny\\alfa.txt
alfa.txt is a file end exists, beta.txt is the new one and does not exists.
I'am running it on a windows 2000 with Java version 1.4.1_01

The strange thing is that if run this piece of code it works !

File xFileTasso = new File("d:\\paolib\\java\\prove\\rtlny\\alfa.txt");
File xNewFileTasso = new File("d:\\paolib\\java\\prove\\rtlny\\beta.txt");

boolean success;
success = xFileTasso.renameTo(xNewFileTasso);
if (!success) {
jOptionPane1.showMessageDialog(this, "Errore rename:" + xFileTasso.toString());
}

Hope someone can help me to sort out this problem.
Thank you very much.
Paolo
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Try entering the file in the gui as d:\paolib\java\prove\rtlny\alfa.txt


[How To Ask Questions On JavaRanch]
paolo colombini
Greenhorn

Joined: Jun 09, 2004
Posts: 4
I have tried this way as well, but no luck.
Might it be a problem of permission ?
Thank you very much for your suggestion.
Paolo
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Works fine for me. Compare this code to yours.


I don't think permissions are much of a problem on Windows computers.
paolo colombini
Greenhorn

Joined: Jun 09, 2004
Posts: 4
I agree. It is not a problem of permission.
I tried to read and write back the file using:

and it worked.
I copied your code and run it with my files and it worked !!
I modified my original code this way

and it did not work. No exception at all !!
I really do not understand what I am doing wrong.
I'll keep on investigating.
Thank you very much for your patience and help.
Paolo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: renameTo() problem