Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

renameTo() problem

 
paolo colombini
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try entering the file in the gui as d:\paolib\java\prove\rtlny\alfa.txt
 
paolo colombini
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic