java.nio.file.FileSystemException:C:\p12\dummy.p12:进程无法访问该



我有一个p12文件上传功能,代码如下:

-

然后我想创建一个函数来删除p12文件,代码如下:

-

当我运行结果时,出现了一个错误:

java.nio.file.FileSystemException: C:p12dummy.p12: The process cannot access the file because it is being used by another process.

有没有办法成功删除文件?

更新:我发现了这个问题,显然是因为p12文件用于这个函数:

-

是否还有办法删除p12文件

异常告诉您有另一个进程打开了该文件,因此无法删除该文件。查看Windows中的系统进程(很可能是应用程序(,看看哪个应用程序打开了文件。您是否在记事本等文本编辑器或命令行shell中打开该文件?你必须在那里关闭它才能删除它。

您打开文件

InputStream keyStoreStream = new FileInputStream(fileDir);

但资源从未关闭。在尝试使用资源块时将相关部件封装起来

Map<String, String> certSn;
try (InputStream keyStoreStream = new FileInputStream(fileDir)) {
certSn =  = getP12Cert(keyStoreStream, passphrase.getPassphrase());
// set up your assigneeModel here
} catch (IOException e) {
// TODO throw or handle the exception however you need to
}
// rest of code here

最新更新