【发布时间】:2016-02-21 17:13:09
【问题描述】:
在我的要求中,我的项目文件夹中有一个图像,如果数据库不包含图像,我会在弹出窗口中显示默认图像
点击PDF按钮后,它执行以下方法:
public void getImage(ExpenseTO to) {
ExpenseTO fetchEntityById = accountService.fetchEntityById(
ExpenseTO.class, to.getExpenseId());
byte[] fileScanned = fetchEntityById.getUploadedScanedFile();
if (fileScanned.length <= 20) {
try {
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("file.png");
byte[] bytes = IOUtils.toByteArray(input);
outPutPdfToDisplay = new DefaultStreamedContent(
new ByteArrayInputStream(bytes));
} catch (Exception e) {
e.printStackTrace();
}
} else {
outPutPdfToDisplay = new DefaultStreamedContent(
new ByteArrayInputStream(fileScanned));
}
}
它执行时没有任何异常但不显示
弹出窗口中的图像
【问题讨论】:
标签: java bytearray inputstream