Java.nio.Files.move is throwing exception when moving files multiple times. please give a solution.
com.aspose.cells.Workbook sortinWorkbook;
String FILE_NAME=“D:\Websites\OrginalFile.xlsx”;
sortinWorkbook=new com.aspose.cells.Workbook(FILE_NAME);
File checkDirectory=new File(FILE_NAME);
if(checkDirectory.exists()){
Files.move(Paths.get(FILE_NAME), Paths.get(“D:\Websites\WindowsService\TempFiles\TempSorting.xlsx”));
}
sortinWorkbook.save(FILE_NAME);
@Raj1995Java,
Thanks for the code segment and details.
I have evaluated your scenario/ case a bit. The issue is not related to Aspose.Cells APIs by any means. To resolve your issue, you may try using/setting StandardCopyOption.REPLACE_EXISTING option for java.nio.file.Files.move() overloaded method. See the updated code segment which works fine as I tested:
e.g
Sample code:
........
for(int i = 0;i<6;i++)
{
com.aspose.cells.Workbook sortinWorkbook;
String FILE_NAME="f:\\files\\OriginalFile.xlsx";
sortinWorkbook=new com.aspose.cells.Workbook(FILE_NAME);
File checkDirectory=new File(FILE_NAME);
if(checkDirectory.exists()){
Files.move(Paths.get(FILE_NAME), Paths.get("e:\\test2\\TempSorting1.xlsx"), StandardCopyOption.REPLACE_EXISTING);
}
sortinWorkbook.save(FILE_NAME);
}
By the way, you do not need to move the file to other location as Aspose.Cells would automatically replace the existing file (remove the existing file and generate new).
1 Like
i’m trying Aspose.Cells workbook.save() but i got java.io.FileNotFoundException
and How to send Filepath into workbook without FileInputStream?
please find my attachement of project soruce
Soruce.zip (3.2 KB)
@Raj1995Java,
Thanks for the sample code.
The exception “java.io.FileNotFoundException” is related to java.io
and does not have any links to Aspose.Cells APIs, please make sure that you specify valid path in Workbook.save() method. I have also checked the source code a bit and found you are also using apache.poi API with Aspose.Cells for Java. Please create a simple Java program and only use Aspose.Cells for Java API (without involving other Excel spreadsheet management APIs) to reproduce the issue, we will check it soon.
1 Like