ºìÁªLinuxÃÅ»§
Linux°ïÖú

JAVA»ù´¡£º´Ó.classÎļþÖÐÑ°ÕÒÀàÃû

·¢²¼Ê±¼ä:2006-11-22 00:36:23À´Ô´:ºìÁª×÷Õß:Heroop
¿ÉÒÔÓжàÖÖ·½Ê½ÅжÏÀàµÄÃû×Ö£º

¼Ù¶¨ËùÓеÄÀ඼ÒÔcom£¬org£¬»òÕßnet¿ªÍ·
ËÑË÷classpathÀ´Ñ°ÕÒÃû×ÖΪHackµÄÀà
ËÑË÷classpathÀ´Ñ°ÕÒÓ³Éäµ½Õâ¸öÎļþµÄĿ¼Èë¿Ú
Ö±½Ó²é¿´Àà×ÔÉí¡£¶ÔÓÚËùÓеÄÇé¿öÏ£¬ÕâÊÇ×îÖ±½ÓµÄ
Java¹æ·¶¹æ¶¨ÁËÈçºÎ²é¿´Ò»¸öclassÎļþ¡£´æ´¢ÔÚclassÎļþÒ»¿ªÊ¼µÄÒ»¸öÖµ¾ÍÊÇÒÔJavaÄÚ²¿·Ö¸î·û¡°/¡±Îª¸ñʽµÄÍêÕûµÄÀàÃ÷¡£

ÏÂÃæµÄ´úÂë·µ»ØÁËÎļþC:\code\hacks\research\com\generationjava\Hack.classµÄÄÚ²¿ÀàÃûcom/generationjava/Hack£¬¶ÁÕß¿ÉÒÔ½øÒ»²½±àд´úÂ뽫¡°/¡±×ª»»³É¡°.¡±£º

static final public int MAGIC = 0xCAFEBABE;
// ´«µÝC:\code\hacks\research\com\generationjava\Hack.class
// ¼Ù¶¨´æÔÚÕâÑùÒ»¸öÀà
public String getFullyQualifiedName(String filename) throws IOException {
String name = null;

try {
DataInputStream in = new
DataInputStream(new FileInputStream(filename));
if(in.readInt() != MAGIC) {
// ²»ÊÇÒ»¸ö.classÎļþ
thrownew IOException("Not a class file");
}

in.readUnsignedShort();// ´Î°æ±¾ºÅ
in.readUnsignedShort();// Ö÷°æ±¾ºÅ
in.readUnsignedShort();// ³¤¶È
in.readByte();// CLASS=7
in.readUnsignedShort();// ºöÂÔÕâ¸öµØ·½
in.readByte();// UTF8=1
name =in.readUTF();//ÀàµÄÃû×Ö!!!
in.close();
} catch(IOException ioe) {
ioe.printStackTrace();
}

return name;
}
µ±ÄãÖ±½Ó´Ó.classÎļþÖлñµÃÀàµÄÐÅÏ¢µÄʱºò£¬¾Í¼ò»¯ÁË¿ª·¢¡£²éÕÒÒ»¸öÄäÃû.classÀàÎļþµÄÍêÕûµÄÀàÃûÊÇÈκλùÓÚ.classÎļþ¹¤×÷µÄÓ¦ÓõÄÖØÒª²¿¼þ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 2709 ÌõÆÀÂÛ

  1. 72.232.206.* ÓÚ 2006-11-29 11:33:00·¢±í:

    Great work!
    My homepage | Cool site