首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > Apache >

Apache Jakarta Commons 工具集简介及其API拾掇

2012-12-28 
Apache Jakarta Commons 工具集简介及其API整理map.nextKey(FIVE) // returns SIX map.nextKey(SIX

Apache Jakarta Commons 工具集简介及其API整理

map.nextKey("FIVE"); // returns "SIX"
map.nextKey("SIX"); // returns "SEVEN"

五、Commons Configuration

http://try {
InputStreamReader inR = new InputStreamReader( in );
BufferedReader buf = new BufferedReader( inR );
String line;
while ( ( line = buf.readLine() ) != null ) {
System.out.println( line );
}
} finally {
in.close();
}

使用IOUtils

InputStream in = new URL( "http://try {
System.out.println( IOUtils.toString( in ) );
} finally {
IOUtils.closeQuietly(in);
}

2.读取文件

File file = new File("/commons/io/project.properties");
List lines = FileUtils.readLines(file, "UTF-8");

3.察看剩余空间
long freeSpace = FileSystemUtils.freeSpace("C:/");

十一、Commons JXPath

http://
// List the children of the Jar file
FileObject[] children = jarFile.getChildren();
System.out.println( "Children of " + jarFile.getName().getURI() );
for ( int i = 0; i < children.length; i++ ){
System.out.println( children[ i ].getName().getBaseName() );
}

从smb读取文件
StaticUserAuthenticator auth = new StaticUserAuthenticator("username", "password", null);
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileObject fo = VFS.getManager().resolveFile("smb://host/anyshare/dir", opts);

十八、Commons-Email

commons-email是5. validateObject is invoked in an implementation-specific fashion to determine if an instance is still valid to be returned by the pool. It will only be invoked on an "activated" instance.


二十、Commons Digester

它能方便地将XML文档所定义的元素转化为JAVA对象,其实它的用法有点象栈(当然内在的原理就是那个古老的东西,只是提供了更高一层的封装)。

//生成一个digester。主要需要引进commons-logging.jar、commons-collections.jar、commons- beanutils.jar
Digester digester = new Digester();

//设置对XML文档资料是否进行DTD验证
digester.setValidating( false );

//当遇见 catalog 元素的时候,产生一个Catalog对象
digester.addObjectCreate( "catalog", Catalog.class );

//当遇见 catalog 元素下面的book的时候,产生一个Book对象
digester.addObjectCreate( "catalog/book", Book.class );
// 当遇见 catalog 元素下面的book的author时候,调用author属性的Set方法
digester.addBeanPropertySetter( "catalog/book/author", "author" );
digester.addBeanPropertySetter( "catalog/book/title", "title" );
//当再一次遇见 catalog 元素下面的book的时候,调用catalog类的addBook()方法
digester.addSetNext( "catalog/book", "addBook" );

digester.addObjectCreate( "catalog/magazine", Magazine.class );
digester.addBeanPropertySetter( "catalog/magazine/name", "name" );

digester.addObjectCreate( "catalog/magazine/article", Article.class );
//addSetProperties()是将对应元素的属性赋值。
digester.addSetProperties( "catalog/magazine/article", "page", "page" );
digester.addBeanPropertySetter( "catalog/magazine/article/headline" );
digester.addSetNext( "catalog/magazine/article", "addArticle" );

digester.addSetNext( "catalog/magazine", "addMagazine" );
//"F:\\Digester\\catalog.xml"为XML文档
File input = new File( "F:\\Digester\\catalog.xml" );
Catalog c = (Catalog)digester.parse( input );
System.out.println( c.toString() );

?

热点排行