• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Rename Excel File using Java

 
Greenhorn
Posts: 6
Mac PPC Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am trying to rename the excel file using but, it was not successful . Please help me out

String path = "C:\Users\nvr\Desktop\sample.xls";
File file = new File(path);

File file2 = new File(file.getParentFile().getPath() + "/" + "temp_" + file.getName());

boolean success = file.renameTo(file2);

if (!success) {
System.out.println("File was not successfully renamed");
} else {
System.out.println("File was successfully renamed");
}

I got the output as : File was not successfully renamed

Can you let me know, If i am messing up anything in here or is there any other way to rename the xls files.

Thanks,
NVR
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either file2 already exists, or the Excel file is still open - either by an external application (Excel itself?) or by an input / output stream from your Java application.
 
nv reddy
Greenhorn
Posts: 6
Mac PPC Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, My input Stream is Still open. It solved the Issue. Thank You so much. Have a great day.
 
Their achilles heel is the noogie! Give them noogies tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic