ZipInputStream的有关问题 散200分~

ZipInputStream的问题 散200分~~~~解压zip文件不含中文但是用ZipInputStream解压出来的文件跟源文件比较有

ZipInputStream的问题 散200分~~~~
解压zip文件     不含中文

但是   用ZipInputStream解压出来的文件跟源文件比较有差异
(表现为   某些地方会添加0x20   即空格     文件尾缺少     原以为是缓冲的问题   不停的flush也没用)

使用ZipFile的正确  

想问问是什么原因     那些0x20是怎么多出来的

代码如下

使用ZipInputStream解压     (解压不正确)  

public   class   ZipTest2
{
        private   static   int   length   =   9;
        public   static   void   main(String[]   args)   throws   IOException
        {
                File   f1   =   new   File( "C:\\test.zip ");
               
                ZipInputStream   zin   =   new   ZipInputStream(new   FileInputStream(f1));
               
                ZipEntry   zinentry;
               
                while((zinentry   =   zin.getNextEntry())   !=   null)
                {
                        File   f   =   new   File( "C:\\ "   +   zinentry.getName());
                        if(!f.exists())
                        {
                                if(zinentry.isDirectory())
                                        f.mkdirs();
                                else
                                        f.createNewFile();
                        }
                        if(zinentry.isDirectory())
                        {
                                zin.closeEntry();
                                continue;
                        }
                        FileOutputStream   output   =   new   FileOutputStream(f);
                        long   size   =   zinentry.getSize();
                        while(size   > =   length)
                        {
                                System.out.println(size);


                                byte[]   bytes   =   new   byte[length];
                                zin.read(bytes,0   ,   length);
                                output.write(bytes,   0,   length);
//                                 output.flush();
                                size   -=   length;
                        }
                       
                        if(size   >   0   &&   size   <   length)
                        {
                                System.out.println(size);
                                byte[]   bytes   =   new   byte[(int)size];
                                zin.read(bytes,   0,   (int)size);
                                output.write(bytes,   0,   (int)size);
//                                 output.flush();
                        }
                        output.close();
                       
                        zin.closeEntry();
                       
                }
               
                zin.close();
        }
}


使用ZipFile解压     (解压正确)

public   class   ZipTest3
{
        private   static   int   length   =   2048;

        public   static   void   main(String[]   args)   throws   IOException
        {
                File   f   =   new   File( "C:\\test.zip ");
                ZipFile   zipf   =   new   ZipFile(f);

                Enumeration   zipEntrys   =   zipf.entries();

                while   (zipEntrys.hasMoreElements())
                {


                        ZipEntry   zipEntry   =   (ZipEntry)   zipEntrys.nextElement();
                        File   tempf   =   new   File( "C:\\ "   +   zipEntry.getName());

                        if   (!tempf.exists())
                        {
                                if   (zipEntry.isDirectory())
                                        tempf.mkdirs();
                                else
                                        tempf.createNewFile();
                        }

                        InputStream   input   =   zipf.getInputStream(zipEntry);
                        FileOutputStream   output   =   new   FileOutputStream(tempf);
                        long   size   =   zipEntry.getSize();
                       
                        while(size   > =   length)
                        {
                                byte[]   bytes   =   new   byte[length];
                                input.read(bytes);
                                output.write(bytes);
//                                 output.flush();
                               
                                size   -=   length;
                        }
                       
                        if(size   >   0   &&   size   <   length)
                        {
                                byte[]   bytes   =   new   byte[(int)size];
                                input.read(bytes);


                                output.write(bytes);
//                                 output.flush();
                        }
                        input.close();
                        output.close();

                }
               
                zipf.close();
        }
}


[解决办法]
不懂,帮顶
[解决办法]
再加个修饰类呢??例如: BufferedInputStream,BufferedOutputStream
在这个基础上再用ZipInputStream 不知道如何??
[解决办法]
帮顶
[解决办法]
帮顶

[解决办法]
ding
[解决办法]
帮顶
[解决办法]
你的代码可以说都写得有点问题
应该是
int readed = zin.read(bytes,0 , length);
output.write(bytes, 0, readed);//read方法并不保证它全部read到你指定的length


int readed = input.read(bytes);
output.write(bytes, 0, readed);
[解决办法]
同意楼上说法,用循环拉
比如
int totalLength = getTotalLengthInSomeWay();
int lengthRead = 0;
while(lengthRead <totalLength){
lengthRead += zin.read(bytes,lengthRead,totalLength-lengthRead);
}