使用读取文件流的形式
使用读取文件流的形式private Image loadImage() {
//加载文件PDF_HEADER_PATH
try (InputStream input = this.getClass()
.getResourceAsStream(ExperimentConstants.PDF_HEADER_PATH);
ByteArrayOutputStream output = new ByteArrayOutputStream()){
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return Image.getInstance(output.toByteArray());
} catch (IOException | BadElementException e) {
System.err.println("未能正确加文件");
return null;
}
}



