java得到一个包的所有类
public static Class[] getClasses(String pckgname)
throws ClassNotFoundException {
ArrayList<Class> classes = new ArrayList<Class>();
// Get a File object for the package
File directory = null;
try {
ClassLoader cld = Thread.currentThread().getContextClassLoader();
if (cld == null)
throw new ClassNotFoundException("Can't get class loader.");
String path = '/' + pckgname.replace('.', '/');
URL resource = cld.getResource(path);
if (resource == null)
throw new ClassNotFoundException("No resource for " + path);
directory = new File(resource.getFile());
} catch (NullPointerException x) {
throw new ClassNotFoundException(pckgname + " (" + directory
+ ") does not appear to be a valid package a");
}
if (directory.exists()) {
// Get the list of the files contained in the package
String[] files = directory.list();
for (int i = 0; i < files.length; i++) {
// we are only interested in .class files
if (files[i].endsWith(".class")) {
// removes the .class extension
classes.add(Class.forName(pckgname + '.'
+ files[i].substring(0, files[i].length() - 6)));
}
}
} else
throw new ClassNotFoundException(pckgname
+ " does not appear to be a valid package b");
Class[] classesA = new Class[classes.size()];
classes.toArray(classesA);
return classesA;
}
这个方法是从sun论坛上找到的,他在eclipse的tomcat6.0环
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
Java网络编程初步
Kagula
2009-11-23
关键词
Java Socket DataInputStream DataOutputStream
概要
使用Java同步IO应用程序库,实现CS结构网络编程。
正文
使用Socket来建立网络连接,使用DataInputStream、DataOutputStream来存取网络流。
客户端部份
第一步 ......
一、Java基础知识
1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别。
2.字符串的操作:
写一个方法,实现字符串的反转,如:输入abc,输出cba
写一个方法,实现字符串的替换,如:输入bbbwlirbbb,输出bbbhhtccc。
3.数据类型之间的转换
如何将数值型字符转换为数字( ......