Java 7新特性(三) ——更多NIO APIs
JSR 203:NIO 2扩展和实现了在Java 1.4中加入的最初NIO功能。在NIO 2中最明显的新增功能就是文件访问API的全面改进。多数开发者都用过java.io.File,对其存在的众多缺陷自然心中有数:
◆不支持符号链接(symbolic links )
◆不支持简单移动和拷贝操作
◆目录漫游和过滤API非常复杂
◆对文件属性和访问权限的支持非常有限
◆没有查看目录或文件的API
◆有限的错误处理功能
幸运的是,JSR 203不仅改进了以上所有缺点,而且实现了更多功能。这个API从一开始就设计为具备可扩展性,除了支持默认文件系统外,还支持嵌入式文件系统,还具有诸多灵活选项设置,可以实现诸如打开和拷贝文件、系统属性定义等操作。
Listing 2演示了JSR 203是如何被用来实现一些通用操作。Path是这个API的核心;你可以把它看作新建文件。
Listing 2
import java.nio.file.*;
// FileSystems -> FileSystem -> Path
FileSystem fileSystem = FileSystems.getDefault();
Path homeDir = fileSystem.getPath("/Users/lskywalker");
// Shortcut with Paths helper class
Path homeDir = Paths.get("/Users/lskywalker");
Path secrets = homeDir.resolve("secrets.txt");
// Steal secrets
secrets.moveTo(Paths.get("/Users/dvader/secrets.txt"));
除了文件系统API外,JSR 203还实现了许多在第一版NIO中提出的API,提供了对组播的更多支持,提供了在Socket和文件上进行异步I/O操作的API。
相关文档:
本次主要以例子为主:
1.匹配图像 /**
* 匹配图象 <br>
* 格式: /相对路径/文件名.后缀 (后缀为gif,dmp,png)
* 匹配 : /forum/head_icon/admini2005111_ff.gif 或 admini2005111.dmp<br>
* 不匹配: c:/admins4512.gif
*/
public static final String icon_regexp = "^(/{0,1}\ ......
估计学习java的买了Bruce Eckle《Thinking In Java 4th Edition》的新手们(我也是),估计多会遇到一个问题:
编译时import static net.mindview.util.Print.*;找不到相应的包,print方法就用不了。下面把我的操作方法贴出来,希望能帮到你。
1、把书本的源代码 ......
if(null != agent && -1 != agent.indexOf("MSIE")){
filename = URLEncoder.encode(filename
,"UTF8");
}else if ......
计算某一月份的最大天数
Calendar time=Calendar.getInstance();
time.clear();
time.set(Calendar.YEAR,year); //year 为 int
time.set(Calendar.MONTH,i-1);//注意,Calendar对象默认一月为0
int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);/ ......
Here is a simple library to query Google Maps with the following features:
geocode addresses to their geographic coordinates
retrieve static images with given custom size, format and zoom
To see a live sample of this API, you can check here: Java ME Google Maps API sample MIDlet
Contents
[h ......