File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Rename Excel File using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Rename Excel File using Java" Watch "Rename Excel File using Java" New topic
Author

Rename Excel File using Java

nv reddy
Greenhorn

Joined: Sep 21, 2011
Posts: 6

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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
nv reddy
Greenhorn

Joined: Sep 21, 2011
Posts: 6

Yes, My input Stream is Still open. It solved the Issue. Thank You so much. Have a great day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rename Excel File using Java