java - Class creating by copying doesnt work -


i following exmaple in asm 4.0 manual, in section explains visitor there exmaple of copying class using code similar this:

    inputstream in=asmhelloworld.class.getresourceasstream("test.class");     classwriter cw = new classwriter(0);     classreader cr = new classreader(in);     cr.accept(cw, 0);     byte[] b2 = cw.tobytearray(); // b2 represents same class b1 

the difference in book define input data byte array dont know how read class byte array, instead used example found online read class inputstream.

i save class using following code:

    dataoutputstream os = new dataoutputstream(new fileoutputstream("test2.class"));     os.write(b2);     os.flush();     os.close(); 

the thing when try run test2 following error:

error: not find or load main class test2 

the size of test.class , test2.class same

in copy have test1.class file test class name. generated class must have same name file name before .class


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -