错误 "install JCE Unlimited Strength Jurisdiction Policy files"
Error "install JCE Unlimited Strength Jurisdiction Policy files"
我在 java 中为 Excel 使用 Apache POI 库。我需要用密码打开 xlsx 文件。为什么我有这个错误:"Exception in thread "main“org.apache.poi.EncryptedDocumentException:出口限制到位 - 请安装 JCE Unlimited Strength Jurisdiction Policy 文件”。我试着安装这个文件。但这并没有解决问题。
public static void ReadFromExcell(String file) throws IOException, GeneralSecurityException {
String excelFilePath = "ServerList.xlsx";
try {
NPOIFSFileSystem fileSystem = new NPOIFSFileSystem(new File(excelFilePath));
EncryptionInfo info = new EncryptionInfo(fileSystem);
Decryptor decryptor = Decryptor.getInstance(info);
if (!decryptor.verifyPassword("qwerty")) {
System.out.println("Unable to process: document is encrypted.");
return;
}
InputStream dataStream = decryptor.getDataStream(fileSystem);
Workbook workbook = new XSSFWorkbook(dataStream);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
System.out.print(cell.getStringCellValue() + "\t");
}
System.out.println();
}
workbook.close();
dataStream.close();
fileSystem.close();
} catch (GeneralSecurityException | IOException ex) {
ex.printStackTrace();
}
}
enter image description here
我找到了解决问题的方法。我只替换了文件夹 "jre" 中的文件。还需要替换文件夹"jdk".
中的文件
我在 java 中为 Excel 使用 Apache POI 库。我需要用密码打开 xlsx 文件。为什么我有这个错误:"Exception in thread "main“org.apache.poi.EncryptedDocumentException:出口限制到位 - 请安装 JCE Unlimited Strength Jurisdiction Policy 文件”。我试着安装这个文件。但这并没有解决问题。
public static void ReadFromExcell(String file) throws IOException, GeneralSecurityException {
String excelFilePath = "ServerList.xlsx";
try {
NPOIFSFileSystem fileSystem = new NPOIFSFileSystem(new File(excelFilePath));
EncryptionInfo info = new EncryptionInfo(fileSystem);
Decryptor decryptor = Decryptor.getInstance(info);
if (!decryptor.verifyPassword("qwerty")) {
System.out.println("Unable to process: document is encrypted.");
return;
}
InputStream dataStream = decryptor.getDataStream(fileSystem);
Workbook workbook = new XSSFWorkbook(dataStream);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
System.out.print(cell.getStringCellValue() + "\t");
}
System.out.println();
}
workbook.close();
dataStream.close();
fileSystem.close();
} catch (GeneralSecurityException | IOException ex) {
ex.printStackTrace();
}
}
enter image description here
我找到了解决问题的方法。我只替换了文件夹 "jre" 中的文件。还需要替换文件夹"jdk".
中的文件