Chào các bạn, hiên tại mình có đoạn code tạo file .mht như sau:
@SuppressWarnings({ "unchecked", "rawtypes" })
public Result<String> parseMessage(String certificateUrl,
HttpServletRequest request, BigDecimal classId, BigDecimal agentId,
String language) {
FileInputStream fis = null;
txtBody = new StringBuffer();
htmlBody = new StringBuffer();
attachments = new ArrayList();
urlImage = new ArrayList<String>();
Result<String> result = new Result<String>();
try {
String destinationPath = request.getSession().getServletContext()
.getRealPath(ExcelConstant.EXCEL_TEMP_FOLDER);
// Get stream from file
File file = new File(LMSInit.getConfig().getResourceLocation()
+ Constant.SEPARATOR + certificateUrl);
fis = new FileInputStream(file);
Message mimeMsg = new Message(fis);
BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(destinationPath + fileName + ".html"),
"UTF-8"));
result.setData(ExcelConstant.EXCEL_TEMP_FOLDER + fileName + ".html");
StringBuffer htmlBodyTemp = new StringBuffer();
htmlBodyTemp.append(replaceHmlString(htmlBody.toString(), classId,
agentId, language));
String strHtmlBody = htmlBodyTemp.toString();
String characterReplace = "Content-Location:";
for (String url : urlImage) {
url = url.substring(url.indexOf(characterReplace)
+ characterReplace.length(), url.length() - 1);
url = url.trim();
String imageName = FilenameUtils.getName(url);
strHtmlBody = strHtmlBody.replace(url, fileName + "_files"
+ File.separator + imageName);
}
// write contents of StringBuffer to a file
bwr.write(strHtmlBody);
// flush the stream
bwr.flush();
// close the stream
bwr.close();
} catch (IOException ex) {
result.setStatus(Constant.INTERNAL_SERVER_ERROR);
result.setErrorCode(ErrorCode.CAN_NOT_VIEW_CERTIFICATE);
ex.fillInStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ex) {
result.setStatus(Constant.INTERNAL_SERVER_ERROR);
result.setErrorCode(ErrorCode.CAN_NOT_VIEW_CERTIFICATE);
ex.printStackTrace();
}
}
}
return result;
}
Vấn đề mình gặp phải là lúc tạo new File ở trên thì sẽ tạo được file:
C:\workplace_ws9\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\public\course\313260\certificate(UnitLink)_Final2.mht
Nhưng thay vì tạo ra file certificate(UnitLink)_Final2.mht thì nó lại tạo ra folder có tên certificate(UnitLink)_Final2.mht nên FileInputStream không thể đọc được folder này.
Ai biết cho mình hỏi lỗi này do đâu và làm sao thể tạo ra file mht thay vì folder vậy?

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?