我在java中打开PDF时遇到错误 这是我的代码:
<%@ page language="java"
import="java.util.*,
java.io.*,
java.lang.*,
com.eb.util.PropertyUtil,
javax.portlet.*,
com.ub.ac.Aeans.*,
com.ub.pm.Wob,com.eb.ac.AService,
javax.xml.bind.DatatypeConverter,com.eb.patientChecklist.portlets.*;"
pageEncoding="ISO-8859-1"%><%@ taglib
uri="http://java.sun.com/portlet_2_0" prefix="portlet"%><portlet:defineObjects />
<%
response.reset();
response.setContentType("application/pdf");
String wobId = resourceRequest.getParameter("wobId");
String fileName = resourceRequest.getParameter("fileName");
String dir = PropertyUtil.getPropertyValue("DOC_BASE") + wobId
+ "/" + fileName;
int count = new File(dir).list().length-1;
System.out.println("dir hi :" + dir);
String root = dir + "/" + count + ".pdf";
File pdfFile = new File(root);
response.setContentLength((int) pdfFile.length());
System.out.println("path :" + root);
FileInputStream reader = new FileInputStream(pdfFile);
int line;
OutputStream responseOutputStream = response.getOutputStream();
while ((line = reader.read()) != -1) {
responseOutputStream.write(line);
System.out.print(line);
}
%>
当我删除此行时:
response.reset();
该文件已被调用,但在浏览器中,但它显示的内容如下:
ava教程PDF)/创作者( )/制片人( wkhtmltopdf) / CreationDate(D:20130708155338-05'00')&gt;&gt; endobj 3 0 obj&lt;&lt; /类型 / ExtGState / SA true / SM 0.02 / ca 1.0 / CA 1.0 / AIS false / SMask / None&gt;&gt; endobj 4 0 obj [/ Pattern / DeviceRGB] endobj 8 0 obj [0 / XYZ 34.0799999 807.919999 0] endobj 9 0 obj [0 / XYZ 39.8400000 636.079999 0] endobj 10 0 obj&lt;&lt; / Type / Annot / Subtype / Link / Rect [34.0799999 772.399999 283.680000 782.959999] / Border [0 0 0] / A&lt;&lt; /类型/动作/ S / URI / URI(http://www.tutorialspoint.com/java/java_pdf_version.htm)&gt;&gt; &GT;&GT; endobj 12 0 obj&lt;&gt; endobj 13 0 obj&lt;&gt; endobj 11 0 obj&lt;&gt; endobj 14 0 obj&lt;&lt;
然后当我退回这一行时:
response.reset();
它在控制台中显示我的错误:
getWriter EJPPC0175E:getOutputStream之后无法获取编写器 称为
抱歉我的英语不好