欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用asm工具复制类的字节码到单独的文件中,asm字节码,如下代码实现赋值类的字节

来源: javaer 分享于  点击 27641 次 点评:257

使用asm工具复制类的字节码到单独的文件中,asm字节码,如下代码实现赋值类的字节


如下代码实现赋值类的字节码到单独的class文件中:

package cn.outofmemory;import java.io.FileOutputStream;import java.io.IOException;import org.objectweb.asm.ClassAdapter;import org.objectweb.asm.ClassReader;import org.objectweb.asm.ClassVisitor;import org.objectweb.asm.ClassWriter;public class CopyClass {    public static void main(String[] args) throws Exception {        ClassWriter out=new ClassWriter(0);        ClassVisitor cv=new ClassAdapter(out);        ClassReader cr=new ClassReader("HelloWorld");        cr.accept(cv, 0);        output("/tmp/HelloWorld.class",  out.toByteArray());    }    public static void output(String filename, byte[] data) throws IOException {        FileOutputStream out=new FileOutputStream(filename);        out.write(data);        out.close();    }}
相关栏目:

用户点评