压缩文件的压缩时候中文乱码码

导入

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;

设置gbk  需放在第一行  找这个错找了半天  

/**
* 压缩文件
* @param inputStream
* @param zipoutputStream
* @param fileName
* @throws IOException
*/
public static void zipFile(InputStream inputStream,ZipOutputStream zipoutputStream,String fileName) throws IOException {
zipoutputStream.setEncoding("gbk");
BufferedOutputStream bos = new BufferedOutputStream (zipoutputStream) ;

ZipEntry ze = new ZipEntry(fileName); //获取文件名
zipoutputStream.putNextEntry(ze); // 设置ZipEntry对象
byte [ ] b = new byte [ 100 ] ;
while ( true )
{
int len = inputStream.read ( b ) ;
if ( len == - 1 )
break ;
bos.write ( b , 0 , len ) ;
}

}

posted @ 2018-08-24 13:46  未来有熊  阅读(666)  评论(0编辑  收藏  举报