方法如下:
(388) protected String getExtension(BufferedInputStream stream) throws IOException, MimeTypeException {
(389) TikaConfig config = TikaConfig.getDefaultConfig();
(390) MediaType mediaType = config.getMimeRepository().detect(stream, new Metadata());
(391) MimeType mimeType = config.getMimeRepository().forName(mediaType.toString());
(392) String extension = mimeType.getExtension();
(393) return extension;
(394) }
这是堆栈:
java.io.IOException: The process cannot access the file because another process has locked a portion of the file
The process cannot access the file because another process has locked a portion of the file
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:328)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:291)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:347)
at java.base/java.io.BufferedInputStream.implRead(BufferedInputStream.java:420)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:399)
at java.base/java.io.FilterInputStream.read(FilterInputStream.java:95)
at org.apache.tika.mime.MimeTypes.readMagicHeader(MimeTypes.java:325)
at org.apache.tika.mime.MimeTypes.detect(MimeTypes.java:527)
at com.mbm.mediaorganizer.RelocateFileVisitor.getExtension(RelocateFileVisitor.java:390)
at com.mbm.mediaorganizer.RelocateFileVisitor.relocateFile(RelocateFileVisitor.java:163)
at com.mbm.mediaorganizer.RelocateFileVisitor.visitFile(RelocateFileVisitor.java:79)
at com.mbm.mediaorganizer.RelocateFileVisitor.visitFile(RelocateFileVisitor.java:1)
at java.base/java.nio.file.Files.walkFileTree(Files.java:2810)
at java.base/java.nio.file.Files.walkFileTree(Files.java:2881)
at com.mbm.mediaorganizer.MediaOrganizer.run(MediaOrganizer.java:214)
at com.mbm.mediaorganizer.MediaOrganizer.main(MediaOrganizer.java:63)
从调用堆栈中,您可以看到在进入公开可用的 jar 文件之前执行的最后一行代码是:
(RelocateFileVisitor.java:390)
但是我的代码中的第 390 行位于一个声明它的方法中
throws IOException
。 为什么执行在第 390 行停止并且没有渗透到调用堆栈?
您误读了堆栈跟踪。异常已传播。