Note that there are some explanatory texts on larger screens.

plurals
  1. PODecompress string in java from compressed string in C#
    text
    copied!<p>I was searching for the correct solution to decompress the string in java coming from c# code.I tried myself with lot of techniques in java like(gzip,inflatter etc.).but didn't get the solution.i got some error while trying to decompress the string in java from compressed string from c# code.</p> <p>My C# code to compress the string is,</p> <pre><code>public static string CompressString(string text) { byte[] byteArray = Encoding.GetEncoding(1252).GetBytes(text);// Encoding.ASCII.GetBytes(text); using (var ms = new MemoryStream()) { // Compress the text using (var ds = new DeflateStream(ms, CompressionMode.Compress)) { ds.Write(byteArray, 0, byteArray.Length); } return Convert.ToBase64String(ms.ToArray()); } } </code></pre> <p>And decompress the string in java using,</p> <pre><code>private static void compressAndDecompress(){ try { // Encode a String into bytes String string = "xxxxxxSAMPLECOMPRESSEDSTRINGxxxxxxxxxx"; // // Compress the bytes byte[] decoded = Base64.decodeBase64(string.getBytes()); byte[] output = new byte[4096]; // Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(decoded); int resultLength = decompresser.inflate(output); decompresser.end(); // Decode the bytes into a String String outputString = new String(output, 0, resultLength, "UTF-8"); System.out.println(outputString); } catch(java.io.UnsupportedEncodingException ex) { ex.printStackTrace(); } catch (java.util.zip.DataFormatException ex) { ex.printStackTrace(); } } </code></pre> <p>I get this exception when running the above code:</p> <pre><code>java.util.zip.DataFormatException: incorrect header check </code></pre> <p>Kindly give me the sample code in java to decompress the string java.Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload