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

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