-4

I would like to save an exisiting excel with a new name. but the contents should be same. It should perform the save as property for any any excel. please help

  • possible duplicate of [How to rename a file using java.io packages?](http://stackoverflow.com/questions/6080295/how-to-rename-a-file-using-java-io-packages) – Srinath Ganesh Sep 09 '13 at 05:51

1 Answers1

1

contents rename and save as

Quoting duplicate post

File oldfile = new File(old_name);
File newfile = new File(new_name);
boolean rename = oldfile.renameTo(newfile);

API:

Returns true if and only if the renaming succeeded; false otherwise

Note : Constructing the file object does NOT create a file on disk!


UPDATES : since @prasanth said question is about save as feature I am adding that part

For save as feature

reference from duplicate post

    FileChannel src = new FileInputStream(file1).getChannel();   
    FileChannel dest = new FileOutputStream(file2).getChannel();   
    dest.transferFrom(src, 0, src.size());
// also close FileChannel  objects
Community
  • 1
  • 1
Srinath Ganesh
  • 2,496
  • 2
  • 30
  • 60