I need to convert a PHP code to Java. One of the functions converts a zip file to a URL-encoded format. I use the same zipped folder (containing a .csv file in it).
In PHP using this code, I get this response
$file = "batch.zip";
echo file_get_contents($file);
Response: PK �mSRbatch/PKjRR_I��75*batch/batch_2020-08-31-14-43-09 - Copy.csv�M-.NLO�)��I+���I�O��K��JIK)N+N�1107��4�446�1�����5��PK �mSR$batch/ V*u��V*u��C~1p��PKjRR_I��75*$ $batch/batch_2020-08-31-14-43-09 - Copy.csv S{�-���"�t�����s��PK��
But when I try to open the same file in Java (I am using Maven) I get this response
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream file = classloader.getResourceAsStream("batch.zip");
StringBuilder textBuilder = new StringBuilder();
try (Reader reader = new BufferedReader(new InputStreamReader
(file, Charset.forName(StandardCharsets.UTF_8.name())))) {
int c = 0;
while ((c = reader.read()) != -1) {
textBuilder.append((char) c);
}
}
System.out.println("textBuilder = " + textBuilder.toString());
Response: textBuilder = PK
�mSR batch/PK jRR_I��7 5 * batch/batch_2020-08-31-14-43-09 - Copy.csv�M-.NLO�)��I+���I�O��K��JIK)N+N�1107��4�446�1�����5�� PK
�mSR $ batch/
V*u��V*u��C~1p��PK jRR_I��7 5 * $ $ batch/batch_2020-08-31-14-43-09 - Copy.csv
S{�-���"�t�����s��PK � �
Besides the many space that exists in the file read with Java, I get some missing characters too. Any help? My final goal is to read a zip file, encode it to base 64 and url encode it in the end