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环
相关文档:
-A-
AJAX: (建议不译,原因:专有名词) [Asynchronous JavaScript and XML,异步JavaScript及XML]
annotation: 注解
Ant: (建议不译,原因:专有名词)
AOP: (建议不译,原因:专有名词) [aspect-oriented programming, 面向层面编程]
application: 应用
argument: 参数
-B-
B2B: (建议不译,原因:专有名词) ......
from: http://mmblue.javaeye.com/blog/511915
package org.mmblue.common.util;
import java.util.List;
public class PageModel<T> {
// ......
一、Java基础知识
1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别。
2.字符串的操作:
写一个方法,实现字符串的反转,如:输入abc,输出cba
写一个方法,实现字符串的替换,如:输入bbbwlirbbb,输出bbbhhtccc。
3.数据类型之间的转换
如何将数值型字符转换为数字( ......
众所周知,在程序开发中,难免会遇到需要匹配、查找、替换、判断字符串的情况发生,而这些情况有时又比较复杂,如果用纯编码方式解决,往往会浪费程序员的时间及精力。因此,学习及使用正则表达式,便成了解决这一矛盾的主要手段。
大
家都知道,正则表达式是一种可以用于模式匹配和替换的规范,一个正则表达 ......
java中科学计数法的解除
数据过大或接近于0,java会自动使用科学计数法显示
要使得数据以正常的小数显示可使用DecimalFormat类:
DecimalFormat format = new DecimalFormat("0.00000");
String value = format.format(doubleInstance);
......