user3588565
user3588565

Reputation: 3

is it possible to change name of excel file created using java

I have created an excel file using Java but, now I want to give dynamic name to excel file rather than static name using Java. I am currently using POI library.

I have created excel using following code:

WritableWorkbook copy = Workbook.createWorkbook(new File("/sdcard/mattress.xls"));
WritableSheet sheet = copy.createSheet("First Sheet", 0);

Consider another excel file having list of names. So, I want to rename this file mattress.xls with different names fetched from another excel file within program. Suggest me with best possible way.

Upvotes: 0

Views: 4064

Answers (2)

Anil Jadhav
Anil Jadhav

Reputation: 2158

You can rename file by using the below code,

File sdcard = new File("File Directory Path");
File from = new File(sdcard,"from.txt");
File to = new File(sdcard,"to.txt");
from.renameTo(to);

Upvotes: 0

Scary Wombat
Scary Wombat

Reputation: 44834

The constructor for File takes a String that can be any valid filename.

So

 String myFile = getStringForMyLogic ();
 WritableWorkbook copy = Workbook.createWorkbook(new File(myFile));

Upvotes: 1

Related Questions