You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hadoop.apache.org by lk_hadoop <lk...@163.com> on 2016/10/21 08:19:14 UTC

question about hdfs FSDataOutputStream

hi,all:
I wan to uncompress .zip file under hdfs . code like this:

                    ZipInputStream zipInputStream = null;
                    FSDataOutputStream mergerout = null;
                    try{
                        zipInputStream = new ZipInputStream(in);
                        //解压后有多个文件一并解压出来并实现合并
                        //合并后的地址
                        ZipEntry entry;
                        Path p = new Path(hdfsOutPath + File.separator + inputFiles[i].getPath().getName().substring(0, inputFiles[i].getPath().getName().indexOf("."))+"unzip");
                        System.out.println("输出文件名>> "+p.toUri().toString());
                        mergerout = hdfs.create(p);
                        while((entry = zipInputStream.getNextEntry()) != null){
                         System.out.println("带解压文件实体>> "+entry.getName());
                            byte[] buffer1 = new byte[4096];
                            int nNumber;
                            while((nNumber = zipInputStream.read(buffer1,0, buffer1.length)) != -1){
                             //System.out.println("输出字节数>> "+nNumber);
                             mergerout.write(buffer1, 0, nNumber);
                            }
                        }
                        mergerout.flush();
                    }catch(IOException e){
                     e.printStackTrace();
                        continue;
                    }finally{
                     if(mergerout!=null){
                      System.out.println("mergerout.close() "+mergerout.size());
                      mergerout.close();
                      
                     }
                     if(zipInputStream!=null){
                      zipInputStream.close();
                     }
                        if(in!=null){
                         in.close();
                        }
                    }

The line in red color,if Ididn't add suffix for example "unzip" to make output filename different from the zip file name , I will got nothing in output path,even the path is a different folder .
Who can tell me why ?

2016-10-21


lk_hadoop