FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
char[] chrBuffer = new char[10];
int intLength;
while((intLength=fr.read(chrBuffer))!=-1){
out.write(chrBuffer,0,intLength);
} 页面输出WORD文件出现乱码. 请问错在哪里, 并给出范例.
BufferedReader br = new BufferedReader(fr);
char[] chrBuffer = new char[10];
int intLength;
while((intLength=fr.read(chrBuffer))!=-1){
out.write(chrBuffer,0,intLength);
} 页面输出WORD文件出现乱码. 请问错在哪里, 并给出范例.
response.setHeader("Content-disposition","inline; filename=mc.doc");
String path = request.getRealPath("../Files");
FileReader fr = new FileReader(path + "\\" + fileName);
BufferedReader br = new BufferedReader(fr);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
//bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bis = new BufferedInputStream(new FileInputStream(path + "\\" + fileName));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(FileNotFoundException fe){
System.out.println("文件没找到");
} catch(final IOException e) {
System.out.println ( "出现IOException." + e );
} 请问如何在jsp中直接读取word文档,把其内容转成html格式显示
An error occurred at line: 140 in the jsp file: /office.jsp
The method invoke(Dispatch, String, int, Object[], int[]) in the type Dispatch is
not applicable for the arguments (Object, String, int, Object[], int[])137: try {
138: app.setProperty("Visible", new Variant(false)); //设置word不可见
139: Object docs = app.getProperty("Documents").toDispatch();
140: Object doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
141: // 打开word文件
142: Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(8) }, new int[1]);
143: // 作为html格式保存到临时文件
BufferedReader br = new BufferedReader(fr);
char[] chrBuffer = new char[1024]; //char值放大一些就可以了。
int intLength;
while((intLength=fr.read(chrBuffer))!=-1){
out.write(chrBuffer,0,intLength);
}
<%
response.setContentType("msword/html");
response.setHeader("Content-disposition","inline; filename=mc.doc");
String path = request.getRealPath("../Files");
FileReader fr = new FileReader(path + "\\" + fileName); //
BufferedReader br = new BufferedReader(fr); //建立BufferedReader对象,并设定由br对象变量引 BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
//bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bis = new BufferedInputStream(new FileInputStream(path + "\\" + fileName));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(FileNotFoundException fe){
System.out.println("文件没找到");
} catch(final IOException e) {
System.out.println ( "出现IOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
out.clear();
out = pageContext.pushBody();
}
br.close(); //关闭BufferedReader对象
fr.close(); //关闭文件
%>
</div>想让文件输出在<DIV> 之间,可目前效果是在整个页面里打开输出了这个DOC文件.
<%
response.setContentType("msword/html");
response.setHeader("Content-disposition","inline; filename=mc.doc");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(fileName));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(FileNotFoundException fe){
System.out.println("文件没找到");
} catch(final IOException e) {
System.out.println ( "出现IOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
br.close(); //关闭BufferedReader对象
fr.close(); //关闭文件
%>
</div>Content-disposition是什么意思?