Java Package getPackages()方法
java.lang.Package.getPackages() 方法获取所有目前已知调用方的ClassLoader实例的软件包。这些包对应于通过加载或名称至ClassLoader实例访问的类。如果调用者的ClassLoader实例是引导类加载器的实例,这可能是null,在一些实现来表示,对应于由引导类加载器实例加载的类仅包将被返回。
1 语法
public static Package[] getPackages()
2 参数
无
3 返回值
此方法返回已知调用方的ClassLoader实例程序包的新数组。如果没有已知的,返回0长度数组。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java Package getPackages()方法
*/
public class PackageDemo {
public static void main(String[] args) {
// get all the packages
Package[] pack = Package.getPackages();
// print all packages, one by one
for (int i = 0; i < pack.length; i++) {
System.out.println("" + pack[i]);
}
}
}
输出结果为:
package sun.util, Java Platform API Specification, version 1.6
package java.util, Java Platform API Specification, version 1.6
package java.net, Java Platform API Specification, version 1.6
package sun.reflect.misc, Java Platform API Specification, version 1.6
package sun.security.provider, Java Platform API Specification, version 1.6
package sun.net.www.protocol.jar, Java Platform API Specification, version 1.6
package sun.security.action, Java Platform API Specification, version 1.6
package java.nio.charset, Java Platform API Specification, version 1.6
package sun.io, Java Platform API Specification, version 1.6
package java.io, Java Platform API Specification, version 1.6
package sun.nio, Java Platform API Specification, version 1.6
package sun.net.www, Java Platform API Specification, version 1.6
package java.lang.ref, Java Platform API Specification, version 1.6
package java.lang, Java Platform API Specification, version 1.6
package sun.misc, Java Platform API Specification, version 1.6
package sun.net.www.protocol.file, Java Platform API Specification, version 1.6
package java.util.concurrent, Java Platform API Specification, version 1.6
package java.util.concurrent.atomic, Java Platform API Specification, version 1.6
package com.yiibai
package java.nio.charset.spi, Java Platform API Specification, version 1.6
package java.nio, Java Platform API Specification, version 1.6
package java.util.concurrent.locks, Java Platform API Specification, version 1.6
package sun.reflect, Java Platform API Specification, version 1.6
package java.security, Java Platform API Specification, version 1.6
package java.lang.reflect, Java Platform API Specification, version 1.6
package sun.nio.cs, Java Platform API Specification, version 1.6
package sun.security.util, Java Platform API Specification, version 1.6
package java.security.cert, Java Platform API Specification, version 1.6
package sun.jkernel, Java Platform API Specification, version 1.6
package sun.net.util, Java Platform API Specification, version 1.6
热门文章
优秀文章