3 Replies Latest reply on Nov 27, 2005 10:11 AM by John Coleman

    ClassFile write creates bad byte code

    John Coleman Newbie

      I've followed this example from notes:

      BufferedInputStream fin
      = new BufferedInputStream(new FileInputStream("Point.class"));
      ClassFile cf = new ClassFile(new DataInputStream(fin));

      And then used the write method to create the new class. However, tad throws an exception, so it appears the bytecode is invalid.

      Here is my code:

      InputStream is = getClass().getResourceAsStream(resourceName);
      DataInputStream dis = new DataInputStream(is);
      ClassFile cf = new ClassFile(dis);
      DataOutputStream dos = new DataOutputStream(new FileOutputStream(
      rtDirName + File.separator + "new" + ".class"));

      Any ideas what is wrong? If I use the CtClass regular methods to augment the code, it creates valid byte code.