我不知道,我怎样才能读取文件。我想阅读 FK.java 文件,但给我一个类未找到异常。FK 是注解 java 文件。(我试过“src/annotations/FK.java”但没有用。
private static String clazz = "src/annotations/FK";
public static List<Object> GetAnnotations() throws ClassNotFoundException{
Class<?> c;
c = Class.forName(clazz);
List<Object> result = new ArrayList();
Field[] fields = c.getDeclaredFields();
for (int j = 0; j < fields.length; j++)
{
Annotation[] annot = fields[j].getAnnotations();
for (int k = 0; k < annot.length; k++)
{
result.add(annot[k].annotationType());
}
}
return result;
}
public static void main(String[] args) throws ClassNotFoundException {
System.out.println(GetAnnotations());
}