Reputation: 3
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
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
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