In Aspose for Java, is there a way to detect the file type using only a stream (ex. ByteArrayInputStream, DataInputStream, etc.)? I am trying to convert to PDF with several different file types and I need to do it in memory with streams, not files.
Regarding Aspose.Cells for Java to detect MS Excel spreadsheets or other file formats, you may try to use FileFormatUtil.detectFileFormat(InputStream stream) overload for your requirements.
e.g. Sample code:
File file = new File("f:\\files\\Book1.xlsx");
byte[] array = Files.readAllBytes(file.toPath());
ByteArrayInputStream stream = new ByteArrayInputStream(array);
// Detect file format from streams
FileFormatInfo info = FileFormatUtil.detectFileFormat(stream);
if(info.getFileFormatType() == FileFormatType.XLSX)
{
System.out.print("this is XLSX");
}
else if(info.getFileFormatType() == FileFormatType.ODS)
{
System.out.print("this is ODS");
}
else if(info.getFileFormatType() == FileFormatType.XLSM)
{
System.out.print("this is XLSM");
}
else if(info.getFileFormatType() == FileFormatType.DOCX)
{
System.out.print("this is DOCX");
}
//.......
Moreover, regarding other Aspose for Java APIs (e.g., Aspose.Words, Aspose.PDF, Aspose.Slides), our colleagues from other teams will give details and assist you for your requirements soon.
var info = PresentationFactory.getInstance().getPresentationInfo(inputStream);
// Returns a value from the LoadFormat enumeration.
var fileFormat = info.getLoadFormat();
System.out.println(fileFormat);