• 0

transfer ZIP file through socket


Question

Receive ZIP file side

                    FileOutputStream fileStream=new FileOutputStream(file);
                    ZipOutputStream zip=new ZipOutputStream(fileStream);
                    //zip.putNextEntry(new ZipEntry("1.zip"));
                    byte[] buffer=new byte[1024];
                    int readByte;
                    while((readByte=in.read(buffer))>0){
                        System.out.println(readByte);
                        zip.write(buffer,0,readByte);
                        totalVal-=readByte;
                    }
                    fileStream.close();

Send ZIP file side

                    File file=new File(email+"/"+name+".zip");
                    FileInputStream fileStream=new FileInputStream(file);
                    ZipInputStream zis=new ZipInputStream(new BufferedInputStream(fileStream));
                    out.writeUTF("#SendZIP#");
                    out.writeLong(file.length());
                    byte[] buffer=new byte[1024];
                    int readByte;
                    while((readByte=fileStream.read(buffer))>0){
                        out.write(buffer,0,readByte);
                    }
                    System.out.println("Sendingess");
                     fileStream.close();

actually, I don't know how to use ZipInputStream, even though I search google for whole day.....

could anyone teach me how to send ZIP file~

Thanks very much !!!

Link to comment
https://www.neowin.net/forum/topic/953914-transfer-zip-file-through-socket/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

ZipInputStream and ZipOutputStream are used for reading/writing entries from/to a zip file. If you're just wanting to send a zip file, it's not different than sending the images you were sending (i.e. open a FileInputStream and write to the connection and then read from the socket normally and write it using a FileOutputStream). If you want to read the files out of a zip file or write files into a zip, then that's what you'd use ZipInputStream and ZipOutputStream for.

  • 0
  On 17/11/2010 at 04:52, kjordan2001 said:

ZipInputStream and ZipOutputStream are used for reading/writing entries from/to a zip file. If you're just wanting to send a zip file, it's not different than sending the images you were sending (i.e. open a FileInputStream and write to the connection and then read from the socket normally and write it using a FileOutputStream). If you want to read the files out of a zip file or write files into a zip, then that's what you'd use ZipInputStream and ZipOutputStream for.

oh~!!!that's right!! thanks a lot~I thought it should decode first.

Thanks again!!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.