• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

renameTo() problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic