创建具有阿拉伯字符zip文件 [英] create zip files with arabic characters

查看:121
本文介绍了创建具有阿拉伯字符zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的情况
我要修改现有的文件,并返回一个包含此修改文件的zip,我在Web应用程序上下文
我现在做的最多的是:

i have the following situation i have to modify an existing files and return a zip containing this modified files , i'm in web application context what i done up to now is :

///////////////// modifying the existing file with poi librairy 
    FileInputStream inpoi = new   FileInputStream("file_path");
                POIFSFileSystem fs = new POIFSFileSystem(inpoi);
                HWPFDocument doc = new HWPFDocument(fs);
                Range r = doc.getRange();
                r.replaceText("<nomPrenom>","test"); 
               byte[] b =   doc.getDataStream();

//////////////////////// create the zip file and copy the modified files into it 
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("my.zip"));
out.putNextEntry(new ZipEntry("file"));
for (int j = 0; j < b.length; j++) {
                out.write(b[j]);
              } 

创建的压缩文件不能正确使用Word鉴于原始文件在阿拉伯语wrotten读

the created zipped file can't be read correctly with word given that the original file is wrotten in arabic

我试过这样:

 try {
                 FileInputStream inpoi = new FileInputStream("C:\\Users\\free\\Desktop\\myworkspace\\gestionRH\\WebRoot\\fiches\\blame.doc");
                    POIFSFileSystem fs = new POIFSFileSystem(inpoi);
                    HWPFDocument doc = new HWPFDocument(fs);
                    Range r = doc.getRange();
                    r.replaceText("<nomPrenom>","test"); 
                  byte[] stream=   doc.getDataStream();
                  String encoding = "utf-16";
                  ZipOutputStream out = new ZipOutputStream(new FileOutputStream("yyy.zip"));
                   ZipEntry zipEntry = new ZipEntry("file.doc");
                   OutputStreamWriter writer = new OutputStreamWriter(out,"utf-8");
                    out.putNextEntry(zipEntry);
                    for (int j = 0; j < stream.length; j++) {
                        writer.write(stream[j]);  
                  }
                  writer.close();
                } catch (IOException e) {
                  System.out.println(e.toString());
                }

这是行不通的。

推荐答案

有一个老的bug在java中的zip实现。它应固定在第7版。 http://bugs.sun.com/view_bug.do?bug_id=4244499

There was an old bug in java zip implementation. It should be fixed in v7. http://bugs.sun.com/view_bug.do?bug_id=4244499

这篇关于创建具有阿拉伯字符zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆