2013-01-10 3 views
0

doc 또는 docx 문서를 Unix 디렉토리에 저장하고 사용자가 첨부 파일을 다운로드 할 수있는 웹 페이지와 통합합니다. 다음 코드를 사용하여 문자를 스트리밍하고 올바른 MIME 형식의 Word 문서로 저장하지만 열 때 가비지 문자가 표시됩니다. 그것은 문자 인코딩 문제와 관련이 있습니다. 어떻게 해결할 수 있을까요? docx4j를 사용해야합니까?Microsoft Word 문서 다운로드 첨부 파일 오류

String fullfilename = filename; 

     File f = new File(fullfilename); 
     int length = 0; 

     ServletOutputStream op = response.getOutputStream(); 
     ServletContext context = getContext(); 
     String mimetype = context.getMimeType(fullfilename); 

     response.setContentType((mimetype != null) ? mimetype 
       : "application/x-download"); 
     response.setContentLength((int) f.length()); 
     response.setHeader("Content-Disposition", "attachment;filename=" 
       + filename); 

     byte[] bbuf = new byte[fullfilename.length()]; 
     DataInputStream in = new DataInputStream(new FileInputStream(f)); 
     while ((in != null) && ((length = in.read(bbuf)) != -1)) { 
      op.write(bbuf, 0, length); 

     } 

     in.close(); 
     op.flush(); 
     op.close(); 

도와주세요. 감사.

+0

docx – JasonPlutext

+0

을 만들거나 수정해야하는 경우가 아니면 어떤 mime 유형을 사용하고 있으며 클라이언트 브라우저 및 운영 체제에서 가비지를 표시해야합니까? – JasonPlutext

+0

파일을 만드는 데 사용할 MIME 유형은 application/msword입니다. 브라우저는 Mozilla Firefox입니다. 감사. 도와주세요. – peterwkc

답변

0

올바른 MIME 형식을 설정 한 후 스레드가 닫혔습니다.

관련 문제