• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Rename Excel File using Java

 
Greenhorn
Posts: 6
Mac PPC Ruby Java
  • Mark post as helpful
  • send pies
  • 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: 21822
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Yes, My input Stream is Still open. It solved the Issue. Thank You so much. Have a great day.
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!