2
디렉토리에서 특정 클래스를 반환하는 다음 java 프로그램이 있습니다. 이 클래스의 패키지 이름을 찾고 싶습니다. 어떻게 할 수 있습니까 ?? 코드가 도움이 될 것입니다.클래스에서 패키지 이름 가져 오기
import java.util.*;
import java.io.*;
public class CreateTestPackage
{
public void execute()
{
List<Class> findClasses(File directory) throws ClassNotFoundException
{
List<Class> classes = new ArrayList<Class>();
if (!directory.exists())
{
return classes;
}
File[] files = directory.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.matches("test.*\\.class");
}
});
for (File file : files)
{
if (file.isDirectory())
{
assert !file.getName().contains(".");
classes.addAll(findClasses(file));
}
else if (file.getName().endsWith(".class"))
{
classes.add(Class.forName(file.getName().substring(0, file.getName().length() - 6)));
}
}
return classes;
}
}
}
감사 마이크 나는이 오류 구문 오류 삽입을 얻고있다 ";" 완료하려면 LocalVariableDeclarationStatement에서 목록 findClasses (파일 디렉토리) 던졌습니다 ClassNotFoundException –
Jony
그냥 ";" "c.getPackage(). getName()"의 끝에서 – Khanser
Khanser의 말은 ... – Mike