Here you can find the source of getClassNameByFile(String filePath, List
private static List<String> getClassNameByFile(String filePath, List<String> className, boolean childPackage) throws UnsupportedEncodingException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; public class Main { private static List<String> getClassNameByFile(String filePath, List<String> className, boolean childPackage) throws UnsupportedEncodingException { List<String> myClassName = new ArrayList<String>(); filePath = URLDecoder.decode(filePath, "utf-8"); File file = new File(filePath); File[] childFiles = file.listFiles(); for (File childFile : childFiles) { if (childFile.isDirectory()) { if (childPackage) { myClassName.addAll(getClassNameByFile(childFile.getPath(), myClassName, childPackage)); }/* w w w . ja v a 2 s . c om*/ } else { String childFilePath = childFile.getPath(); if (childFilePath.endsWith(".class")) { childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf(".")); childFilePath = childFilePath.replace("\\", "."); myClassName.add(childFilePath); } } } return myClassName; } }