jay0830 Posted November 17, 2010 Share Posted November 17, 2010 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 More sharing options...
0 kjordan2001 Posted November 17, 2010 Share Posted November 17, 2010 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. Link to comment https://www.neowin.net/forum/topic/953914-transfer-zip-file-through-socket/#findComment-593390618 Share on other sites More sharing options...
0 jay0830 Posted November 17, 2010 Author Share Posted November 17, 2010 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!! Link to comment https://www.neowin.net/forum/topic/953914-transfer-zip-file-through-socket/#findComment-593390712 Share on other sites More sharing options...
Question
jay0830
Receive ZIP file side
Send ZIP file side
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