您的位置:首页 > 其它

使用ZipEntry进行图片压缩下载,文件夹中文乱码问题

2013-08-30 18:45 495 查看
public class ZipMainTest {
public static void main(String[] args) {
try {
test1();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void test1() throws IOException {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
"D:\\testZip.zip"));
// 实例化一个名称为ab.txt的ZipEntry对象
ZipEntry entry = new ZipEntry("张三/");
// 设置注释
zos.setComment("zip测试for单个文件");
// 把生成的ZipEntry对象加入到压缩文件中,而之后往压缩文件中写入的内容都会放在这个ZipEntry对象里面
zos.putNextEntry(entry);
ZipEntry entry2 = new ZipEntry("张三/ab.txt");
zos.putNextEntry(entry2);
InputStream is = new FileInputStream("D:\\ab.txt");
int len = 0;
while ((len = is.read()) != -1)
zos.write(len);
zos.flush();
is.close();
zos.close();
}
}


import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

使用java.util.zip包下的压缩类,在创建压缩文件时,如果文件名存在中文,则会出现乱码!

解决方案:

换成

org.apache.toos.zip包下的对应类,问题立马解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐