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);
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.