문제

I want to open a specific file and zip it and send the byte array of the zipped result over UDP.

Now I checked the java zip API but it only give me to save the zipped file to the computer and opening it again and send it would be inefficiency.

Is there any way to do what I need without writing an implementation of the compression algorithm of my own ?

도움이 되었습니까?

해결책

You cand wrap your ZipOutputStream around a ByteArrayOutputStream and get the bytes out of the ByteArrayOutputStream. Something like this:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
//write the entries
zos.close();
byte[] bytes = baos.toByteArray();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top