Reputation: 2073
I tried to extract a .class File from the .jar, and it worked, but then I changed something an now i got this error:
java.lang.ClassFormatError: Invalid constant pool index 63
Here's my code:
String path = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile()).getAbsolutePath();
if (path.endsWith("."))
path = path.substring(0, path.length() - 1);
String decodedPath = URLDecoder.decode(path, "UTF-8");
File file = new File(decodedPath + (decodedPath.endsWith("\\") ? "Classfile.class" : "\\Classfile.class"));
InputStreamReader read = new InputStreamReader(FileSync.class.getResourceAsStream("/Classfile.class"));
FileWriter write = new FileWriter(file);
int c;
while ((i = read.read()) > -1) {
write.write(i);
}
write.flush();
read.close();
write.close();
ProcessBuilder builder = new ProcessBuilder(System.getProperty("java.home") + "\\bin\\java.exe", "Classfile", decodedPath + (decodedPath.endsWith("\\") ? "Program.jar" : "\\Program.jar"));
builder.directory(file.getParentFile());
Process process = builder.start();
Can anyone help?
Upvotes: 2
Views: 10539
Reputation: 1504
InputStreamReader
and FileWriter
does implicit bytes <-> char conversion. Since java class files are binary files, use the raw bytes via FileInputStream
and FileOutputStream
.
Probably, you can use a hex editor and open the class files before and after writing to verify what is missing/added in the new class file.
Upvotes: 3