我不知道该如何读取文件。我想阅读FK.java文件,但给我一个没有发现异常的类。 FK是注释java文件。 (我曾尝试 “SRC /注释/ 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());
}
的src /可能是源文件夹,所以类名可能annotations.FK – Polygnome
感谢,它可以读取文件:但有人已经得到了一些教程,我怎样才能读出注释?我的代码不起作用... – blaces
@Polygnome - thx,更正 – Attila