• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rename Excel File using Java

 
nv reddy
Greenhorn
Posts: 6
Java Mac PPC Ruby
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java 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
Java Mac PPC Ruby
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic