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文件出现乱码. 请问错在哪里, 并给出范例.

解决方案 »

  1.   

    byte[] chrBuffer = new byte[10] 试试
      

  2.   

    word文件是二进制的,得包装成字符流
      

  3.   

    bang ni ding ou shi cai niao
      

  4.   

    改成流了,还是乱码  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); 
      
        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格式显示
      

  5.   

    byte[] buff = new byte[2048];   也有了.
      

  6.   

    response.setContentType("msword/html;chasrset=utf-8");   
      

  7.   

    用jacob把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格式保存到临时文件
      

  8.   

    FileReader fr = new FileReader(fileName);  
      BufferedReader br = new BufferedReader(fr);   
      char[] chrBuffer = new char[1024];   //char值放大一些就可以了。
      int intLength;
      while((intLength=fr.read(chrBuffer))!=-1){
      out.write(chrBuffer,0,intLength);
      }  
      

  9.   

    目前是能打开word,输出文件,可想实现的功能是在页面一个区域内输出这个DOC文件, 请问如何限制它输出到这个指定区域中. 目前代码如下:<div style="width:800px; border:1px solid black;word-wrap:break-word;float:right;">
    <%
      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文件.
      

  10.   

    update 急. 如何让文件输出在<DIV> 之间??
      

  11.   

    目的是读取DOC文件,在页面一个区域内显示输出,谁能改写下列代码实现此功能,谢谢.<div style="width:800px; border:1px solid black;word-wrap:break-word;float:right;">
    <%
      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是什么意思?
      

  12.   

    <jsp:include page="/WEB-INF/pages/lottery/cjdlt/lastinfo.jsp"></jsp:include> 用这种办法  将这个标签放在div里就应该可以了
      

  13.   

    <jsp:include page="/WEB-INF/pages/lottery/cjdlt/lastinfo.jsp"></jsp:include> 这是什么!!!!...
      

  14.   

    <jsp:include page="/WEB-INF/pages/lottery/cjdlt/lastinfo.jsp"></jsp:include>有道理,谢