0
我有,當我試圖下載文件此錯誤消息:UT010006:無法調用的getWriter()的getOutputStream()已經調用
無法處理異常!: java.lang.IllegalStateException:UT010006:不能調用getWriter(),getOutputStream()已經調用。
文件已下載但沒有擴展名。所以瀏覽器問我應該用什麼程序來閱讀它。
這是我的下載代碼:
InputStream fileIs = null;
OutputStream output = null;
try {
ExternalContext externalContext = getContext().getExternalContext();
externalContext.responseReset();
externalContext.setResponseContentType(fileToDownload.getMetadata().getMimeType());
externalContext.setResponseContentLength(fileToDownload.getMetadata().getTaille().intValue());
externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileToDownload.getMetadata().getFileName() + "\"");
output = externalContext.getResponseOutputStream();
Response repGetFile = ClientBuilder.newClient()
.target(fileToDownload.getMetadata().getFileURL())
.request().header("Authorization", "Bearer bearercode")
.get();
fileIs = repGetFile.readEntity(InputStream.class);
int readBytes;
byte[] buffer = new byte[1024];
while((readBytes = fileIs.read(buffer)) > 0){
output.write(buffer, 0, readBytes);
}
output.flush();
} catch (IOException ex) {
LOG.log(Level.SEVERE, null, ex);
} finally{
try {
fileIs.close();
output.close();
} catch (IOException ex) {
LOG.log(Level.INFO, null, ex);
}
}