get code from java doc to work
in
Programming Questions
•
4 months ago
I would like to get the example code from java to work:
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/zip/Inflater.html
here it is:
I get:
- // Encode a String into bytes
- String inputString = "blahblahblah??";
- byte[] input = inputString.getBytes("UTF-8");
- // Compress the bytes
- byte[] output = new byte[100];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
- // Decompress the bytes
- Inflater decompresser = new Inflater();
- decompresser.setInput(output, 0, compressedDataLength);
- byte[] result = new byte[100];
- int resultLength = decompresser.inflate(result);
- decompresser.end();
- // Decode the bytes into a String
- String outputString = new String(result, 0, resultLength, "UTF-8");
Unhandled exception type UnsupportedEncodingException
So i use:
import java.util.zip.*; import java.io.*;
and put everything in a try block but i can get multiple things thrown at me.
How can i do this in a clean way?
And if i need to try catch, why doesnt the javadoc show that?
1