场景:获取所有类及名称
(整理或填写表格需要)
效果:
代码:
public static void main(final String[] args) {final File currentDirectory = new File("D:\\workspace\\petro-bcenter\\src\\main\\java\\com" +"\\petrochina\\gsms\\membersync\\dto\\request");final File[] fileList = currentDirectory.listFiles();for (final File file : fileList) {if (file.isFile()) {String name = null;try (final BufferedReader br = new BufferedReader(new FileReader(file))) {String line;while ((line = br.readLine()) != null) {//优先级一:取类注释if (line.startsWith("/**")) {//读取下一行line = br.readLine();if (!line.contains("@")) {name = line.substring(2).replace(";", "") + "\t" + file.getName();System.out.println(name);break;}}//取 @title后面的注释if (line.contains("@title")) {name = line.split("@title")[1].replace(";", "") + "\t" + file.getName();System.out.println(name);break;}}} catch (final IOException e) {e.printStackTrace();}}}}