Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.ClassFormatError:无效的常量池索引63_Java_Pool - Fatal编程技术网

java.lang.ClassFormatError:无效的常量池索引63

java.lang.ClassFormatError:无效的常量池索引63,java,pool,Java,Pool,我试着从.jar中提取一个.class文件,它成功了,但后来我改变了一些东西,现在我遇到了以下错误: java.lang.ClassFormatError: Invalid constant pool index 63 这是我的密码: String path = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getFile()).getAbsolutePath(); if (path.endsWi

我试着从.jar中提取一个.class文件,它成功了,但后来我改变了一些东西,现在我遇到了以下错误:

java.lang.ClassFormatError: Invalid constant pool index 63
这是我的密码:

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();

有人能帮忙吗?

InputStreamReader和
FileWriter
执行隐式字节字符转换。由于java类文件是二进制文件,请通过
FileInputStream
FileOutputStream
使用原始字节


也许,您可以使用十六进制编辑器在编写之前和之后打开类文件,以验证新类文件中缺少/添加了什么。

何时何地出现此错误?当我运行上述代码时,什么都没有发生,process.exitValue()为1。。。当我试图运行我的程序从jar中提取的这个.class文件时,它得到了错误。。。但是这个文件看起来还可以,它和jar中的原始文件大小相同!当我正常地从.jar中提取类文件时,它工作得非常好!是什么阻止了您使用
java-cp xxx.jar yyy.Zzz.class
简单地运行ProcessBuilder?您在文件/类名、嵌入类、引用方面没有问题吗?像这样
InputStreamReader read=新的InputStreamReader(FileSync.class.getResourceAsStream(“/Classfile.class”);OutputStreamWriter write=新的OutputStreamWriter(新文件OutputStream(文件))
任何名称中带有Reader/Writer后缀的java.io类都会进行字节字符转换(默认情况下使用平台的字符编码)。不要尝试上面的方法:
InputStream read=FileSync.class.getResourceAsStream(“/Classfile.class”);OutputStream write=新文件OutputStream(文件)那可能是对的。字符转换将未知字符替换为问号(“?”,ASCII代码63),这解释了对常量池索引63的引用。因此这应该可以工作:
InputStream in=FileSync.class.getResourceAsStream(“/Updater.class”);OutputStream out=新文件OutputStream(文件)工作完美!谢谢:)