How to Detect a File Format and Check if the File is Encrypted

Java code to Detect File Format and Check if the File is Encrypted

The following sample code illustrates how to detect a file format (using the file path) and check its extension. You can also determine whether the file is encrypted.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectFileFormatandCheckFileEncrypted.class);
// Detect file format
FileFormatInfo info = FileFormatUtil.detectFileFormat(dataDir + "Book1.xlsx");
// Gets the detected load format
System.out.println("The spreadsheet format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));
// Check if the file is encrypted.
System.out.println("The file is encrypted: " + info.isEncrypted());