@ahsaniqbalsidiqui sir we are using below code to download file and save it to our system from a link in a mail :
public boolean isFileDownloaded(String urlStr, String file) throws IOException {
URL url = null;
ReadableByteChannel readableByteChannel = null;
FileOutputStream fileOutputStream = null;
FileChannel fileChannel = null;
File f = new File(file);
try {
url = new URL(urlStr);
readableByteChannel = Channels.newChannel(url.openStream());
fileOutputStream = new FileOutputStream(f);
fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
}
}
Now when we are trying to create workbook for the downloaded file, we are getting exception mentioned in the first post.
private Worksheet getWorksheet(String fileName) {
//Workbook workbook = null;
//File path = new File(FILE_LOCATION);
Workbook workbook = null;
Worksheet worksheet = null;
try {
InputStream fis = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(FILE_LOCATION + fileName)));
//workbook = new Workbook(fis);
LoadOptions ls = new LoadOptions(LoadFormat.ODS);
workbook = new Workbook(FILE_LOCATION + fileName/* .substring(0,fileName.lastIndexOf("."))*/,ls );
/*
*
*
* Worksheet worksheet = null; log.info("create worksheet from bytes"); try {
* Workbook workbook = new Workbook(fileName);
*/
worksheet = workbook.getWorksheets().get(0);
} catch (IOException ex) {
} catch (Exception ex) {
ex.printStackTrace();
}
return worksheet;
}
We checked and the file pointer is at zero position as it should be.