/* * 取得某一类所在包的所有类名 不含迭代 */ public static String[] getPackageAllClassName(String classLocation, String packageName){ //将packageName分解 String[] packagePathSplit = packageName.split("[.]"); String realClassLocation = classLocation; int packageLength = packagePathSplit.length; for(int i = 0; i< packageLength; i++){ realClassLocation = realClassLocation + File.separator+packagePathSplit[i]; } File packeageDir = new File(realClassLocation); if(packeageDir.isDirectory()){ String[] allClassName = packeageDir.list(); return allClassName; } return null; } public static void main(String[] args) { String[] str=Demo.getPackageAllClassName("src", "test"); for (int i = 0; i < str.length; i++) { System.out.println(str[i]); } }