如何检测文件格式并检查文件是否加密

Java 检测文件格式并检查文件是否加密的代码

以下示例代码说明了如何检测文件格式(使用文件路径)并检查其扩展名。您还可以确定文件是否已加密。

// 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());