I made a java program with gradle. I have jdk 15 on my computer but in the gradle file I put :
sourceCompatibility = 1.8
targetCompatibility = 1.8
so it can run with java 8.
I send the jar file to someone that uses java 8 and it works perfectly fine. On my computer, it works perfectly fine with java 8 and java 15.
I send the jar file to another person and he gets the following error :
[ERROR)Exceptioninthread'Thread-7"java.lang.NoSuchMethodError:java.io.ByteArrayOutputStream.toString(Ljava/nio/charset/Charset;)Ljava/lang/String;
[ERROR) at fr.bloomenetwork.fatestaynight.packager.Utils.docxToKsFile(Utils.java:84)
[ERROR) at fr.bloomenetwork.fatestaynight.packager.FetchingThread.run(FetchingThread.java:197)
[ERROR) at java.lang.Thread.run(UnknownSource)
I don't undestand why he gets this error if it works fine for me and the other person.
Here is the code that raise the error :
public static void docxToKsFile(InputStream is, String filename) throws IOException {
ZipInputStream zis = new ZipInputStream(is);
ByteArrayOutputStream fos = new ByteArrayOutputStream();
ZipEntry ze = null;
String xmlContent = null;
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().equals("word/document.xml")) {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int len;
while ((len = zis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
xmlContent = new String(fos.toString(StandardCharsets.UTF_8)); //Here is line 84
fos.close();
break;
}
}
fos.close();
String txtContent = xmlContent.replaceAll("</w:p>", "\n");
txtContent = txtContent.replaceAll("<[^>]*/?>", "");
txtContent = txtContent.replaceAll("&", "&");
txtContent = txtContent.replaceAll(""", "\"");
java.nio.file.Files.write(Paths.get(filename), txtContent.getBytes(StandardCharsets.UTF_8));
}
ByteArrayOutputStream#toString(java.nio.charset.Charset)method was introduced in Java 10.