0

Unix ディレクトリに保存された doc または docx ドキュメントがあり、ユーザーが添付ファイルをダウンロードできる Web ページと統合しています。文字をストリーミングし、正しい MIME タイプの Word ドキュメントとして保存する次のコードがありますが、開くと文字化けが表示されるのはなぜですか。文字エンコーディングの問題に関連しています。これを解決するには?docx4j を使用する必要がありますか?

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();

助けてください。ありがとう。

4

1 に答える 1

0

正しい MIME タイプを設定した後、スレッドを閉じました。

于 2013-01-31T07:11:22.537 に答える