62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
File file = new File("e:\\3.txt");
System.out.println(file.getName());
}
public static void premain(String agentArs, Instrumentation inst) throws IOException {
// 初始化配置
inst.addTransformer(new ThunisoftClassFileTransformer());
}
public byte[] transform(ClassLoader loader, String className,
Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
byte[] classfileBuffer) throws IllegalClassFormatException {
className = className.replace('/', '.');
System.out.println(className);
return null;
}
inst.getAllLoadedClasses();
[/quote]
这个我试过,感觉输出出来的类太多了,不只是加载过的类,感觉JDK里的类都会输出来。
是想在transform中拦截File类,监控所有涉及了File类传入文件的操作并记录传入的文件到数据库。[/quote]
这样的话,在transform方法里找你的hello.IOTest类,然后写对应的classVisitor,根据全限定名找调用file类的init方法,并重写即可。没必要改file类
如果我没记错的话,直接改File类的话,实际执行的还是没有改过的类。而且还涉及到类加载器方面的问题。inst.getAllLoadedClasses();
[/quote]
这个我试过,感觉输出出来的类太多了,不只是加载过的类,感觉JDK里的类都会输出来。
是想在transform中拦截File类,监控所有涉及了File类传入文件的操作并记录传入的文件到数据库。inst.getAllLoadedClasses();