﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-Rising Sun </title><link>http://www.blogjava.net/brock/</link><description /><language>zh-cn</language><lastBuildDate>Mon, 06 Apr 2026 13:56:12 GMT</lastBuildDate><pubDate>Mon, 06 Apr 2026 13:56:12 GMT</pubDate><ttl>60</ttl><item><title>Lucene基础篇3 Analyzer</title><link>http://www.blogjava.net/brock/archive/2015/01/07/422100.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 07 Jan 2015 02:11:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2015/01/07/422100.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/422100.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2015/01/07/422100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/422100.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/422100.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 看了网上的许多对于lucene 分词解析的文章一知半解且代码比较老旧，为透彻、系统、全面、深刻的了解分词是怎么一个过程，通过自定义一个分词器来分析理解。 其中分词部分利用ICTCLAS4j接口实现。结构如下所示：    &nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 要实现自定义的ICTCLAS4jAnalyzer必须继承Analy...&nbsp;&nbsp;<a href='http://www.blogjava.net/brock/archive/2015/01/07/422100.html'>阅读全文</a><img src ="http://www.blogjava.net/brock/aggbug/422100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2015-01-07 10:11 <a href="http://www.blogjava.net/brock/archive/2015/01/07/422100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lucene基础篇2 Directory</title><link>http://www.blogjava.net/brock/archive/2015/01/07/422099.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 07 Jan 2015 02:09:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2015/01/07/422099.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/422099.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2015/01/07/422099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/422099.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/422099.html</trackback:ping><description><![CDATA[<p>Lucene <span style="font-family: 宋体;">的</span> Directory<span style="font-family:宋体;">类就像它的意思一样&#8220;目录&#8221;，如&#8220;目录&#8221;不存在，第一次启动被创建，一旦文件被创建，它只能打开阅读，或删除。允许读取和写入随机访问。</span>Java I/O api <span style="font-family:宋体;">不能直接使用，只能通过这个</span>API <span style="font-family:宋体;">。</span>Directory<span style="font-family:宋体;">的实现类可以分为文件目录，内存目录和目录的代理类及工具类。具体如下图所示：</span></p>  <p align="center" style="text-align:center"><img src="http://www.blogjava.net/images/blogjava_net/brock/1.jpg" width="799" height="518" alt="" /><br /></p>  <h3><span style="font-family:宋体;">一：文件目录</span></h3>  <p>SimpleFSDirectory:FSDirectory<span style="font-family:宋体;">的简单实现</span>,<span style="font-family:宋体;">并发能力有限，遇到多线程读同一个文件时会遇到瓶颈，通常用</span>NIOFSDirectory<span style="font-family:宋体;">或</span>MMapDirectory<span style="font-family:宋体;">代替。</span></p>  <p>NIOFSDirectory<span style="font-family:宋体;">：通过</span>java.nio's FileChannel<span style="font-family:宋体;">实行定位读取，支持多线程读（默认情况下是线程安全的）。该类仅使用</span>FileChannel<span style="font-family:宋体;">进行读操作，写操作则是通过</span>FSIndexOutput<span style="font-family:宋体;">实现。</span> </p>  <p><span style="font-family:宋体; color:red">注意：</span><span style="color:red">NIOFSDirectory </span><span style="font-family:宋体;color:red">不适用于</span><span style="color:red">Windows</span><span style="font-family:宋体;color:red">系统</span><span style="font-family: 宋体;">，另外如果一个访问该类的线程，在</span>IO<span style="font-family:宋体;">阻塞时被</span>interrupt<span style="font-family:宋体;">或</span>cancel<span style="font-family:宋体;">，将会导致底层的文件描述符被关闭，后续的线程再次访问</span>NIOFSDirectory<span style="font-family:宋体;">时将会出现</span>ClosedChannelException<span style="font-family:宋体;">异常，此种情况应用</span>SimpleFSDirectory<span style="font-family:宋体;">代替。</span></p>  <p>MMapDirectory<span style="font-family: 宋体;">：通过内存映射进行读，通过</span>FSIndexOutput<span style="font-family:宋体;">进行写的</span>FSDirectory<span style="font-family:宋体;">实现类。使用该类时要保证用足够的虚拟地址空间。另外当通过</span>IndexInput<span style="font-family:宋体;">的</span>close<span style="font-family:宋体;">方法进行关闭时并不会立即关闭底层的文件句柄，只有</span>GC<span style="font-family:宋体;">进行资源回收时才会关闭。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;">为了能适应各个操作系统选择最佳</span>Directory<span style="font-family:宋体;">方案，</span>lucene <span style="font-family:宋体;">提供</span>FSDirectory<span style="font-family:宋体;">类的静态方法</span>open()<span style="font-family:宋体;">实现自适应。</span></p>  <p align="left" style="line-height: 12pt;">&nbsp;<strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">public</span></strong> <strong><span style="font-size: 7.5pt;font-family:Consolas;color:#7F0055;">static</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> FSDirectory open(File path, LockFactory lockFactory) </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">throws</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> IOException {</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">if</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> ((Constants.</span><em><span style="font-size:7.5pt;font-family:Consolas; color:#0000C0;">WINDOWS</span></em><span style="font-size: 7.5pt; font-family: Consolas;"> || Constants.</span><em><span style="font-size:7.5pt;font-family:Consolas; color:#0000C0;">SUN_OS</span></em><span style="font-size: 7.5pt; font-family: Consolas;"> || Constants.</span><em><span style="font-size:7.5pt;font-family:Consolas; color:#0000C0;">LINUX</span></em><span style="font-size: 7.5pt; font-family: Consolas;">)</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; Constants.</span><em><span style="font-size:7.5pt;font-family:Consolas;color:#0000C0;">JRE_IS_64BIT</span></em><span style="font-size: 7.5pt; font-family: Consolas;"> &amp;&amp; MMapDirectory.</span><em><span style="font-size:7.5pt;font-family:Consolas;color:#0000C0;">UNMAP_SUPPORTED</span></em><span style="font-size: 7.5pt; font-family: Consolas;">) {</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">return</span></strong> <strong><span style="font-size: 7.5pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> MMapDirectory(path, lockFactory);</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; } </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">else</span></strong> <strong><span style="font-size: 7.5pt;font-family:Consolas;color:#7F0055;">if</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> (Constants.</span><em><span style="font-size:7.5pt;font-family:Consolas; color:#0000C0;">WINDOWS</span></em><span style="font-size: 7.5pt; font-family: Consolas;">) {</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">return</span></strong> <strong><span style="font-size: 7.5pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> SimpleFSDirectory(path, lockFactory);</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; } </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">else</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> {</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:7.5pt;font-family:Consolas; color:#7F0055;">return</span></strong> <strong><span style="font-size: 7.5pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 7.5pt; font-family: Consolas;"> NIOFSDirectory(path, lockFactory);</span></p>  <p align="left" style="line-height: 12pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; }</span></p>  <p style="line-height:12.0pt;"><span style="font-size: 7.5pt; font-family: Consolas;">&nbsp; }</span></p>  <h3><span style="font-family:宋体;">二：内存目录</span></h3>  <p>RAMDirectory<span style="font-family: 宋体;">：常驻内存的</span>Directory<span style="font-family:宋体;">实现方式。默认通过</span>SingleInstanceLockFactory<span style="font-family:宋体;">（单实例锁工厂）进行锁的实现。<span style="color:red">该类不适合大量索引的情况</span>。<span style="color:red">另外也不适用于多线程的情况</span>。</span>&nbsp;<span style="font-family:宋体;">在索引数据量大的情况下建议使用</span>MMapDirectory<span style="font-family:宋体;">代替。</span>RAMDirectory<span style="font-family:宋体;">是</span>Directory<span style="font-family:宋体;">抽象类在使用内存最为文件存储的实现类，其主要是将所有的索引文件保存到内存中。这样可以提高效率。但是如果索引文件过大的话，则会导致内存不足，因此，小型的系统推荐使用，如果大型的，索引文件达到</span>G<span style="font-family:宋体;">级别上，推荐使用</span>FSDirectory<span style="font-family:宋体;">。</span></p>  <p>NRTCachingDirectory<span style="font-family:宋体;">：是对</span>RAMDirectory<span style="font-family:宋体;">的封装，适用于近乎时时（</span>near-real-time<span style="font-family:宋体;">）操作的环境。</span></p>  <h3><span style="font-family:宋体;">三：</span>Direcotry<span style="font-family:宋体;">的代理类及工具类</span></h3>  <p>FileSwitchDirectory:<span style="font-family:宋体;">文件切换的</span>Directory<span style="font-family:宋体;">实现</span>.<span style="font-family:宋体;">针对</span>lucene<span style="font-family:宋体;">的不同的索引文件使用不同的</span>Directory .<span style="font-family:宋体;">借助</span>FileSwitchDirectory<span style="font-family:宋体;">整合不同的</span>Directory<span style="font-family:宋体;">实现类的优点于一身</span><br /> <span style="font-family:宋体;">比如</span>MMapDirectory,<span style="font-family:宋体;">借助内存映射文件方式提高性能，但又要减少内存切换的可能</span> <span style="font-family:宋体;">，当索引太大的时候，内存映射也需要不断地切换，这样优点也可能变缺点，而之前的</span>NIOFSDirectory<span style="font-family:宋体;">实现</span>java NIO<span style="font-family:宋体;">的方式提高高并发性能，但又因高并发也会导致</span>IO<span style="font-family:宋体;">过多的影响，所以这次可以借助</span>FileSwitchDirectory<span style="font-family:宋体;">发挥他们两的优点。</span></p>  <p>RateLimitedDirectoryWrapper:<span style="font-family:宋体;">通过</span>IOContext<span style="font-family:宋体;">来限制读写速率的</span>Directory<span style="font-family:宋体;">封装类。</span></p>  <p>CompoundFileDirectory<span style="font-family:宋体;">：用于访问一个组合的数据流。仅适用于读操作。对于同一段内扩展名不同但文件名相同的所有文件合并到一个统一的</span>.cfs<span style="font-family:宋体;">文件和一个对应的</span>.cfe<span style="font-family:宋体;">文件内。</span><br /> .cfs<span style="font-family:宋体;">文件由</span>Header<span style="font-family:宋体;">，</span>FileData<span style="font-family:宋体;">和</span>FileCount<span style="font-family:宋体;">组成。</span>.cfe<span style="font-family:宋体;">文件由</span>Header<span style="font-family:宋体;">，</span>FileCount,FileName,DataOffset,DataLength<span style="font-family:宋体;">组成。</span>.cfs<span style="font-family:宋体;">文件中存储着索引的概要信息及组合文件</span><br /> <span style="font-family:宋体;">的数目（</span>FileCount<span style="font-family:宋体;">）。</span>.cfe<span style="font-family:宋体;">文件存储文件目录的条目内容，内容中包括文件数据扇区的起始位置，文件的长度及文件的名称。</span></p>  <p>TrackingDirectoryWrapper<span style="font-family:宋体;">：</span>Directory<span style="font-family:宋体;">的代理类。用于记录哪些文件被写入和删除。</span></p>  <h3><span style="font-family:宋体;">四：</span>Direcotry<span style="font-family:宋体;">读写对象的类图</span></h3>  <p><br /><img src="http://www.blogjava.net/images/blogjava_net/brock/2.jpg" width="825" height="458" alt="" /><br /></p><a href="http://blog.itpub.net/batch.download.php?aid=38503"></a>  <span style="font-size:10.5pt;font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;"><br clear="all" style="page-break-before:always" /> </span>  <p>&nbsp;文章转载过来的！</p><img src ="http://www.blogjava.net/brock/aggbug/422099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2015-01-07 10:09 <a href="http://www.blogjava.net/brock/archive/2015/01/07/422099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在同一台机器上安装多个版本jdk，修改环境变量不生效</title><link>http://www.blogjava.net/brock/archive/2015/01/06/422073.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Tue, 06 Jan 2015 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2015/01/06/422073.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/422073.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2015/01/06/422073.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/422073.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/422073.html</trackback:ping><description><![CDATA[<p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #946f34; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fff0d1;"></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp; &nbsp; 本机已经安装了jdk1.6，而比较早期的项目需要依赖jdk1.5，于是同时在本机安装了jdk1.5和jdk1.6.&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;安装jdk1.5前，执行java -version得到</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">java version "1.6.0_38"<br />Java(TM) SE Runtime Environment (build 1.6.0_38-b05)<br />Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">安装完jdk1.5,并修改环境变量JAVA_HOME为D:\devSoftware\jdk1.5.再执行&nbsp;java -version时，依然显示：</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">java version "1.6.0_38"<br />Java(TM) SE Runtime Environment (build 1.6.0_38-b05)<br />Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)<br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">看上去，新的环境变量JAVA_HOME=D:\devSoftware\jdk1.5并没有生效。 在网上找了很多资料才发现：</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;"><span style="color: #3366ff;"><strong>&nbsp; &nbsp; &nbsp; 在安装JDK1.6时（本机先安装jdk1.6再安装的jdk1.5），自动将java.exe、javaw.exe、javaws.exe三个可执行文件复制到了C:\Windows\System32目录，由于这个目录在WINDOWS环境变量中的优先级高于JAVA_HOME设置的环境变量优先级</strong></span></span><br /></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;"><span style="color: #3366ff;"><strong><br /></strong></span></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;">解决方案：将java.exe,javaw.exe,javaws.exe删除即可。开启新的命令行窗口，再执行java -version时，就得到了期望中的结果<span style="color: #3366ff;"><strong></strong></span></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="text-indent: 28px;">java version "1.5.0_17"<br />Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_17-b04)<br />Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_17-b04, mixed mode)<br /></span></p><div><span style="text-indent: 28px;"><br /></span></div><p style="line-height: 28px; margin: 0px 0px 10px; padding: 0px; color: #946f34; font-family: 'Hiragino Sans GB W3', 'Hiragino Sans GB', Arial, Helvetica, simsun, u5b8bu4f53; font-size: 16px; background-color: #fff0d1; text-indent: 2em;"></p><img src ="http://www.blogjava.net/brock/aggbug/422073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2015-01-06 11:45 <a href="http://www.blogjava.net/brock/archive/2015/01/06/422073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Lucene基础篇1 概论</title><link>http://www.blogjava.net/brock/archive/2014/12/31/421991.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 31 Dec 2014 09:07:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/12/31/421991.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/421991.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/12/31/421991.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/421991.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/421991.html</trackback:ping><description><![CDATA[<p><span style="font-family:宋体;">在学</span>lucene <span style="font-family:宋体;">之初看了许多书，都是走马观花，没有项目的驱动下，来一个用例</span>demo<span style="font-family:宋体;">感觉也不是很难，&#8220;我会了&#8221;这是我的第一感觉。</span></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">在</span>2013<span style="font-family:宋体;">年底公司接到一个项目用到</span>lucene,<span style="font-family:宋体;">这是我第一次正真接触</span>Lucene<span style="font-family:宋体;">，代码比较老</span>3.6<span style="font-family:宋体;">版本，不适合新项目的需求（空间查询）。于是下载了最新版本</span> 4.51,<span style="font-family:宋体;">有带&#8220;空间查询&#8221;模块。各大搜索引擎都没有找到像样例子，于是想到了</span>lucene svn<span style="font-family:宋体;">的</span> trunk<span style="font-family:宋体;">目录测试用例中找到了测试例子，开始了一段</span>lucene<span style="font-family:宋体;">之旅。</span></p><p>&nbsp;</p><p style="text-indent:21.0pt"><span style="font-family:宋体;">写数据，创建</span>IndexWriter,<span style="font-family:宋体;">通过它的构造函数需要一个索引目录（</span>Diectory<span style="font-family:宋体;">）和索引写入配置项（</span>InderWriterConfig<span style="font-family:宋体;">）</span>,<span style="font-family:宋体;">直接上代码：</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">设置写入目录</span><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">(</span><span style="font-size:9.0pt;font-family: 宋体; color:#3F7F5F;">好几种呵呵</span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;">)</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">Directory d=FSDirectory.<em>open</em>(</span><strong><span style="font-size:9.0pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> File(</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"D:/luceneTest"</span><span style="font-size: 9pt; font-family: Consolas;">));</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">设置分词</span><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;"> StandardAnalyzer</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">（会把句子中的字单个分词）</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">Analyzer analyzer= </span><strong><span style="font-size:9.0pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> StandardAnalyzer(Version.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">LUCENE_45</span></em><span style="font-size: 9pt; font-family: Consolas;">);</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">设置索引写入配置</span> </p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">IndexWriterConfig </span>config<span style="font-size: 9pt; font-family: Consolas;">=</span><strong><span style="font-size:9.0pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> IndexWriterConfig(Version.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">LUCENE_45</span></em><span style="font-size: 9pt; font-family: Consolas;">,analyzer);</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">设置创建模式</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);</span></p><p><span style="font-size: 9pt; font-family: Consolas;">IndexWriter <u>indexwriter</u>= </span><strong><span style="font-size:9.0pt; font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> IndexWriter(d,config);</span></p><p>&nbsp;</p><p><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 宋体;">上面四行代码就创建好了</span><u><span style="font-size: 9pt; font-family: Consolas;">indexwriter</span></u><u><span style="font-size: 9pt; font-family: 宋体;">，</span></u><span style="font-size: 9pt; font-family: 宋体;">下面把数据填入就好了，写入有多种方式如下图：</span></p><p><img src="http://www.blogjava.net/images/blogjava_net/brock/1.png" border="0" alt="" width="668" height="128" /><br /></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">用</span> addDocment <span style="font-family:宋体;">举例代码如下：</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">Document doc=</span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> Document();&nbsp; </span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;doc.add(</span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> StringField(</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"id"</span><span style="font-size: 9pt; font-family: Consolas;">, </span><span style="font-size: 9.0pt;font-family:Consolas;color:#2A00FF;">"1"</span><span style="font-size: 9pt; font-family: Consolas;">, Store.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">YES</span></em><span style="font-size: 9pt; font-family: Consolas;">));</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc.add(</span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> StringField(</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"name"</span><span style="font-size: 9pt; font-family: Consolas;">, </span><span style="font-size: 9.0pt;font-family:Consolas;color:#2A00FF;">"brockhong"</span><span style="font-size: 9pt; font-family: Consolas;">, Store.</span><em><span style="font-size:9.0pt;font-family:Consolas;color:#0000C0;">YES</span></em><span style="font-size: 9pt; font-family: Consolas;">));</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doc.add(</span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> TextField(</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"content"</span><span style="font-size: 9pt; font-family: Consolas;">, </span><span style="font-size: 9.0pt;font-family:Consolas;color:#2A00FF;">"lucene </span><span style="font-size:9.0pt; font-family:宋体;color:#2A00FF;">文档第一次写看着给分吧</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"</span><span style="font-size: 9pt; font-family: Consolas;">, Store.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">YES</span></em><span style="font-size: 9pt; font-family: Consolas;">));&nbsp; </span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">写入数据</span></p><p align="left"><span style="font-size: 9pt; font-family: Consolas;">indexwriter.addDocument(doc);</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">提交</span></p><p><span style="font-size: 9pt; font-family: Consolas;">indexwriter.commit();</span></p><p><span style="font-size: 9pt; font-family: 宋体;">用</span><span style="font-size: 9pt; font-family: Consolas;"> Luke </span><span style="font-size: 9pt; font-family: 宋体;">工具查看</span><span style="font-size: 9pt; font-family: Consolas;">Text</span><span style="font-size: 9pt; font-family: 宋体;">列，这是标准分词惹的祸哦！写入成功。</span></p><p><img src="http://www.blogjava.net/images/blogjava_net/brock/2.png" border="0" alt="" width="876" height="686" /><br /></p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family:宋体;">读数据查询，创建</span> IndexSearcher <span style="font-family:宋体;">构造函数设置</span>indexReader <span style="font-family:宋体;">，输入查询条件，上面</span>content<span style="font-family:宋体;">字段数据设置了分词，所以必须通过查询解析类</span>QueryParser<span style="font-family:宋体;">设定分词字段、版本、分词模式，并通过</span>parse<span style="font-family:宋体;">方法得到查询条件。代码如下：</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">&nbsp;//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">读数据</span></p><p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">&nbsp;//</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">创建</span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;"> indexReader </span><span style="font-size: 9.0pt;font-family:宋体;color:#3F7F5F;">这个已过时</span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;"> IndexReader.open(d)</span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">，里面的代码一样可能为了兼容老版本</span></p><p><span style="font-size: 9pt; font-family: Consolas;">&nbsp;IndexReader <u>indexReader</u> = DirectoryReader.<em>open</em>(d);</span></p><p><span style="font-size: 8pt; font-family: Consolas;">&nbsp;IndexSearcher <u>indexSearcher</u> = </span><strong><span style="font-size:8.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 8pt; font-family: Consolas;"> IndexSearcher(indexReader);</span> </p><p align="left"><span style="font-size:7.5pt;font-family:Consolas;color:#3F7F5F;">//</span><span style="font-size:7.5pt;font-family:宋体;color:#3F7F5F;">查询</span> <span style="font-size:7.5pt;font-family:宋体;color:#3F7F5F;">设置分词字段</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">QueryParser queryParser = </span><strong><span style="font-size:8.0pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 8pt; font-family: Consolas;"> QueryParser(Version.</span><em><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">LUCENE_45</span></em><span style="font-size: 8pt; font-family: Consolas;">, </span><span style="font-size: 8.0pt;font-family:Consolas;color:#2A00FF;">"content"</span><span style="font-size: 8pt; font-family: Consolas;">,</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size:8.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 8pt; font-family: Consolas;"> StandardAnalyzer(Version.</span><em><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">LUCENE_45</span></em><span style="font-size: 8pt; font-family: Consolas;">));</span></p><p align="left">&nbsp;<span style="font-size:7.5pt;font-family:Consolas;color:#3F7F5F;">//or </span><span style="font-size:7.5pt; font-family:宋体;color:#3F7F5F;">关系</span> <span style="font-size:7.5pt;font-family: 宋体; color:#3F7F5F;">&#8220;给&#8221;、&#8220;分&#8221;</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; queryParser.setDefaultOperator(QueryParser.</span><em><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">OR_OPERATOR</span></em><span style="font-size: 8pt; font-family: Consolas;">);</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">Query query = queryParser.parse(</span><span style="font-size:8.0pt;font-family:Consolas;color:#2A00FF;">"</span><span style="font-size:8.0pt;font-family:宋体;color:#2A00FF;">给分</span><span style="font-size:8.0pt;font-family:Consolas;color:#2A00FF;">"</span><span style="font-size: 8pt; font-family: Consolas;">);</span></p><p align="left">&nbsp;</p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">TopDocs results = indexSearcher.search(query, 100);</span></p><p align="left"><strong><span style="font-size:8.0pt;font-family:Consolas;color:#7F0055;">int</span></strong><span style="font-size: 8pt; font-family: Consolas;"> numTotalHits = results.</span><span style="font-size:8.0pt; font-family:Consolas;color:#0000C0;">totalHits</span><span style="font-size: 8pt; font-family: Consolas;">;</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">System.</span><em><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">out</span></em><span style="font-size: 8pt; font-family: Consolas;">.println(</span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;">"</span><span style="font-size:8.0pt;font-family:宋体;color:#2A00FF;">共</span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;"> "</span><span style="font-size: 8pt; font-family: Consolas;"> + numTotalHits + </span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;">" </span><span style="font-size:8.0pt;font-family:宋体;color:#2A00FF;">完全匹配的文档</span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;">"</span><span style="font-size: 8pt; font-family: Consolas;">);</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">ScoreDoc[] hits = results.</span><span style="font-size:8.0pt; font-family:Consolas;color:#0000C0;">scoreDocs</span><span style="font-size: 8pt; font-family: Consolas;">;</span> </p><p align="left"><strong><span style="font-size:8.0pt;font-family:Consolas;color:#7F0055;">for</span></strong><span style="font-size: 8pt; font-family: Consolas;"> (</span><strong><span style="font-size:8.0pt;font-family:Consolas; color:#7F0055;">int</span></strong><span style="font-size: 8pt; font-family: Consolas;"> i = 0; i &lt; hits.</span><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">length</span><span style="font-size: 8pt; font-family: Consolas;">; i++) {</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document document = indexSearcher.doc(hits[i].</span><span style="font-size:8.0pt;font-family:Consolas;color:#0000C0;">doc</span><span style="font-size: 8pt; font-family: Consolas;">);</span></p><p align="left"><span style="font-size: 8pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><em><span style="font-size:8.0pt;font-family:Consolas; color:#0000C0;">out</span></em><span style="font-size: 8pt; font-family: Consolas;">.println(</span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;">"content:"</span><span style="font-size: 8pt; font-family: Consolas;"> + document.get(</span><span style="font-size:8.0pt;font-family:Consolas; color:#2A00FF;">"content"</span><span style="font-size: 8pt; font-family: Consolas;">));</span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size: 8pt; font-family: Consolas;">}<o:p></o:p></span></p><p><br /></p>pasting<img src ="http://www.blogjava.net/brock/aggbug/421991.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-12-31 17:07 <a href="http://www.blogjava.net/brock/archive/2014/12/31/421991.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Dom4j SAXReader读取xml异常时占用文件，导致不能移动文件</title><link>http://www.blogjava.net/brock/archive/2014/09/02/417604.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Tue, 02 Sep 2014 06:00:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/09/02/417604.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/417604.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/09/02/417604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/417604.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/417604.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/ablipan/article/details/8198692">http://blog.csdn.net/ablipan/article/details/8198692<br /><br /></a><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;">使用SAXReader的read(File file)方法时，如果xml文件异常会导致文件被服务器占用不能移动文件，建议不使用read(File file)方法而使用read(FileInputStream fis)等流的方式读取文件，异常时关闭流，这样就不会造成流未关闭，文件被锁的现象了。<strong><span style="color: #ff0000;">(在服务器中运行时会锁住文件，main方法却不会)。</span></strong></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;"><strong><span style="color: #ff0000;"><br /></span></strong></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;"><strong>1、以下方式xml文件异常时会导致<span style="color: #ff0000;">文件被锁</span></strong></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div bg_java"="" style="background-color: #ffffff; width: 907.0625px; line-height: 26px;"><div><div><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="view plain">view plain</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="copy">copy</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="print">print</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="?">?</a><div style="position: absolute; left: 760px; top: 592px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document&nbsp;document&nbsp;=&nbsp;null;&nbsp;&nbsp;</li><li style="line-height: 18px;">File&nbsp;file&nbsp;=&nbsp;new&nbsp;File(xmlFilePath);&nbsp;&nbsp;</li><li style="line-height: 18px;">SAXReader&nbsp;saxReader&nbsp;=&nbsp;new&nbsp;SAXReader();&nbsp;&nbsp;</li><li style="line-height: 18px;">try&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;document&nbsp;=&nbsp;saxReader.read(file);&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;catch&nbsp;(DocumentException&nbsp;e)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;logger.error("将文件["&nbsp;+&nbsp;xmlFilePath&nbsp;+&nbsp;"]转换成Document异常",&nbsp;e);&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;</li></ol></div><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><br style="font-family: Arial; line-height: 26px; background-color: #ffffff;" /><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 18px;"><strong>2、以下方式xml文件异常时<span style="color: #ff0000;">不会锁文件</span>(也可以使用其他的流来读文件)</strong></span></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div bg_java"="" style="background-color: #ffffff; width: 907.0625px; line-height: 26px;"><div><div><strong>[java]</strong>&nbsp;<a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="view plain">view plain</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="copy">copy</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="print">print</a><a href="http://blog.csdn.net/ablipan/article/details/8198692#" title="?">?</a><div style="position: absolute; left: 760px; top: 915px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document&nbsp;document&nbsp;=&nbsp;null;&nbsp;&nbsp;</li><li style="line-height: 18px;">FileInputStream&nbsp;fis&nbsp;=&nbsp;null;&nbsp;&nbsp;</li><li style="line-height: 18px;">try&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;fis&nbsp;=&nbsp;new&nbsp;FileInputStream(xmlFilePath);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;SAXReader&nbsp;reader&nbsp;=&nbsp;new&nbsp;SAXReader();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;document&nbsp;=&nbsp;reader.read(fis);&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">catch&nbsp;(Exception&nbsp;e)&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;logger.error("将文件["&nbsp;+&nbsp;xmlFilePath&nbsp;+&nbsp;"]转换成Document异常",&nbsp;e);&nbsp;&nbsp;</li><li style="line-height: 18px;">}&nbsp;&nbsp;&nbsp;</li><li style="line-height: 18px;">finally&nbsp;&nbsp;</li><li style="line-height: 18px;">{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;if(fis&nbsp;!=&nbsp;null)&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fis.close();&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logger.error("将文件["&nbsp;+&nbsp;xmlFilePath&nbsp;+&nbsp;"]转换成Document,输入流关闭异常",&nbsp;e);&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="line-height: 18px;">} &nbsp;</li></ol></div><img src ="http://www.blogjava.net/brock/aggbug/417604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-09-02 14:00 <a href="http://www.blogjava.net/brock/archive/2014/09/02/417604.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenLayers 叠加国家天地图 墨卡托</title><link>http://www.blogjava.net/brock/archive/2014/06/24/415076.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Tue, 24 Jun 2014 09:00:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/06/24/415076.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/415076.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/06/24/415076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/415076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/415076.html</trackback:ping><description><![CDATA[<div></div><div>&lt;head&gt;</div><div>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;</div><div>&lt;title&gt;二次开发示例&lt;/title&gt;</div><div></div><div>&lt;link rel="stylesheet" href="../OpenLayers2.11/theme/default/style.css" type="text/css" /&gt;</div><div>&nbsp; &nbsp; &lt;script type="text/javascript" src="../OpenLayers2.11/OpenLayers.js"&gt;&lt;/script&gt;</div><div>&nbsp; &nbsp; &lt;script type="text/javascript" src="../OpenLayers2.11/OpenLayersEx.js?random=8852c822-1ab8-4c0a-9717-b6f4c2b98115"&gt;&lt;/script&gt;</div><div></div><div>&nbsp;</div><div>&nbsp; &nbsp; &lt;!-- Import OpenLayers, reduced, wms read only version --&gt;</div><div>&nbsp; &nbsp; &lt;!--&lt;script src="../OpenLayers.js" type="text/javascript"&gt;&lt;/script&gt;--&gt;</div><div></div><div>&lt;script type="text/javascript"&gt;</div><div>&nbsp; &nbsp;var map;</div><div></div><div><span style="white-space:pre">	</span> var bounds = new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34);</div><div>function init() {</div><div>&nbsp; &nbsp; var options = {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;controls:[new OpenLayers.Control.XPanZoomBar(),new OpenLayers.Control.Navigation(),new OpenLayers.Control.MousePosition({numDigits:2})] ,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; projection: 'EPSG:900913',</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxResolution: 156543.0339,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; units: 'm',</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; zoomLevel: 8</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</div><div></div><div>&nbsp; &nbsp; map = new OpenLayers.Map('map',options); &nbsp; &nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span>/*{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; div: "map",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; projection: "EPSG:900913",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; units: "m",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; maxExtent: new OpenLayers.Bounds(</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -20037508.34, -20037508.34, 20037508.34, 20037508.34</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; maxResolution: 156543.0339,</div><div><span style="white-space:pre">		</span> zoomLevel: 8</div><div>&nbsp; &nbsp; }*/</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span></div><div>&nbsp; &nbsp;// var osm = new OpenLayers.Layer.OSM();</div><div></div><div>&nbsp; &nbsp; // If tile matrix identifiers differ from zoom levels (0, 1, 2, ...)</div><div>&nbsp; &nbsp; // then they must be explicitly provided.</div><div>&nbsp; &nbsp; var matrixIds = new Array(19);</div><div>&nbsp; &nbsp; for (var i=0; i&lt;16; ++i) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; matrixIds[i] = i+"";</div><div>&nbsp; &nbsp; }</div><div><span style="white-space:pre">	</span> var wmts2 = new OpenLayers.Layer.WMTS({</div><div>&nbsp; &nbsp; &nbsp; &nbsp; name: "Medford Buildings",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; url: "http://t0.tianditu.com/cia_w/wmts",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; layer: "cia",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; matrixSet: "w",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; matrixIds: matrixIds,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; format: "tiles",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; style: "default",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; opacity: 0.7,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; isBaseLayer: false</div><div>&nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;&nbsp;</div><div></div><div>&nbsp; &nbsp; var wmts = new OpenLayers.Layer.WMTS({</div><div>&nbsp; &nbsp; &nbsp; &nbsp; name: "vec",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; url: "http://t0.tianditu.com/vec_w/wmts",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; layer: "vec",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; matrixSet: "w",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; matrixIds: matrixIds,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; format: "tiles",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; style: "default",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; opacity:1,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; isBaseLayer: true</div><div>&nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div></div><div><span style="white-space:pre">	</span></div><div>&nbsp; &nbsp; map.addLayers( [wmts,wmts2]);</div><div>&nbsp; // &nbsp;map.addControl(new OpenLayers.Control.LayerSwitcher());</div><div>&nbsp; // &nbsp;map.setCenter(new OpenLayers.LonLat(13391734.740566667,3535411.228859166),7);</div><div><span style="white-space:pre">	</span> map.moveTo(new OpenLayers.LonLat(13391734.740566667,3535411.228859166),7);</div><div><span style="white-space:pre">	</span></div><div>}</div><div></div><div></div><div>&lt;/script&gt;</div><div>&lt;/head&gt;</div><div>&nbsp;&lt;body onload="init();"&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;h1 id="title"&gt;Web Map Tile Service (WMTS) Layer&lt;/h1&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id="map" class="smallmap"&gt;&lt;/div&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &lt;/body&gt;</div><div>&lt;/html&gt;</div><img src ="http://www.blogjava.net/brock/aggbug/415076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-06-24 17:00 <a href="http://www.blogjava.net/brock/archive/2014/06/24/415076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>投影坐标于经纬度转换</title><link>http://www.blogjava.net/brock/archive/2014/06/20/414956.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Fri, 20 Jun 2014 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/06/20/414956.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/414956.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/06/20/414956.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/414956.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/414956.html</trackback:ping><description><![CDATA[<p>arcgis</p>  <p>CGCS2000_3_Degree_GK_Zone_40</p>  <p><span style="color:#F2F2F2;background:navy;">WKID: 4528 Authority: EPSG</span></p>  <p>&nbsp;</p>  <p>Projection: Gauss_Kruger</p>  <p><span style="color:red">False_Easting: 40500000.0</span></p>  <p><span style="color:red">False_Northing: 0.0</span></p>  <p><span style="color:red">Central_Meridian: 120.0</span></p>  <p><span style="color:red">Scale_Factor: 1.0</span></p>  <p><span style="color:red">Latitude_Of_Origin: 0.0</span></p>  <p><span style="color:red">Linear Unit: Meter (1.0)</span></p>  <p>&nbsp;</p>  <p>Geographic Coordinate System: GCS_China_Geodetic_Coordinate_System_2000</p>  <p>Angular Unit: Degree (0.0174532925199433)</p>  <p>Prime Meridian: Greenwich (0.0)</p>  <p>Datum: D_China_2000</p>  <p>&nbsp; Spheroid: CGCS2000</p>  <p>&nbsp;&nbsp;&nbsp; Semimajor Axis: 6378137.0</p>  <p>&nbsp;&nbsp;&nbsp; Semiminor Axis: 6356752.314140356</p>  <p style="text-indent:21.0pt">Inverse Flattening: 298.257222101</p>  <p style="text-indent:21.0pt">&nbsp;</p>  <p style="text-indent:21.0pt">Java <span style="font-family:宋体;">自定义</span></p>    <p style="text-indent:21.0pt">&nbsp;<div style="display: inline-block;"></div></p><div><span class="Apple-tab-span" style="white-space:pre">	</span>String [] proj4_w = new String [] {&nbsp;</div><p style="text-indent:21.0pt"></p><div><span style="white-space:pre">				</span>"+proj=tmerc",&nbsp;</div><div><span style="white-space:pre">				</span>"+lat_0=0",&nbsp;</div><div><span style="white-space:pre">				</span>"+lon_0=120",&nbsp;</div><div><span style="white-space:pre">				</span>"+ellps=GRS80",&nbsp;</div><div><span style="white-space:pre">				</span>"+units=m",&nbsp;</div><div><span style="white-space:pre">				</span>"+x_0=40500000",</div><div><span style="white-space:pre">				</span>"+y_0=0",</div><div><span style="white-space:pre">				</span>"+k=1.0"</div><div><span style="white-space:pre">				</span>};</div><p style="text-indent:21.0pt"><span style="font-family:宋体;">经纬度转换</span></p>  <p align="left"><span style="font-size: 12pt; font-family: Consolas;">&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; </span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;">///+<u>proj</u>=<u>tmerc</u> +lat_0=0 +lon_0=120 +k=1 +x_0=40500000 +y_0=0 +<u>ellps</u>=GRS80 +units=m +no_defs</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2D.Double srcProjec = </span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">null</span></strong><span style="font-size: 9pt; font-family: Consolas;">;</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2D.Double dstProjec = </span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">null</span></strong><span style="font-size: 9pt; font-family: Consolas;">;</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Projection proj = ProjectionFactory.<em><span style="background:silver;">fromPROJ4Specification</span></em> (proj4_w);</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">//&nbsp; </span><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">"<u>epsg</u>:4528" </span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">数据从</span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;">proj4 </span><span style="font-size:9.0pt;font-family:宋体;color:#3F7F5F;">拷贝</span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;"> nad </span> </p>  <p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2D.Double srcProjec = null;</span></p>  <p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point2D.Double dstProjec = null;</span></p>  <p align="left"><span style="font-size:9.0pt;font-family:Consolas;color:#3F7F5F;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Projection <u>proj</u> = ProjectionFactory.getNamedPROJ4CoordinateSystem ("<u>epsg</u>:4528");</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srcProjec = </span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> Point2D.Double (120.159,30.267); </span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size:9.0pt;font-family:Consolas; color:#3F7F5F;">//40515348.2903 3349745.5395</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dstProjec = proj.transform (srcProjec, </span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> Point2D.Double ());</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">out</span></em><span style="font-size: 9pt; font-family: Consolas;">.println (</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"TM:"</span><span style="font-size: 9pt; font-family: Consolas;"> + dstProjec); </span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9.0pt;font-family:Consolas;color:#3F7F5F;">// TM: Point2D.Double [644904.399587292, 400717.8948938238]</span></p>  <p align="left">&nbsp;</p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srcProjec = </span><strong><span style="font-size:9.0pt;font-family:Consolas; color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> Point2D.Double (40515348.2903 ,3349745.5395); </span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dstProjec = proj.inverseTransform (srcProjec, </span><strong><span style="font-size:9.0pt;font-family:Consolas;color:#7F0055;">new</span></strong><span style="font-size: 9pt; font-family: Consolas;"> Point2D.Double ());</span></p>  <p align="left"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>  <p style="text-indent:21.0pt"><span style="font-size: 9pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.</span><em><span style="font-size:9.0pt;font-family:Consolas; color:#0000C0;">out</span></em><span style="font-size: 9pt; font-family: Consolas;">.println (</span><span style="font-size:9.0pt;font-family:Consolas; color:#2A00FF;">"TM:"</span><span style="font-size: 9pt; font-family: Consolas;"> + dstProjec);</span></p><img src ="http://www.blogjava.net/brock/aggbug/414956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-06-20 11:41 <a href="http://www.blogjava.net/brock/archive/2014/06/20/414956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>电脑非法关机 导致ORA-01033:解决方法</title><link>http://www.blogjava.net/brock/archive/2014/04/30/413091.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 30 Apr 2014 06:38:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/04/30/413091.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/413091.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/04/30/413091.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/413091.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/413091.html</trackback:ping><description><![CDATA[<p>今天研究Oracle遇到了这个问题ora-01033:oracle initializationor shutdown in progress</p><p>ORA-01033:ORACLEinitialization or shutdown in progress</p><p>解决方法</p><p>1)开始-运行-cmd</p><p>2)命令行中输入SQLPLUS SYS/SYS AS SYSDBA</p><p>3)输入SHUTDOWN</p><p>4)输入STARTUP.注意这里是最重要的地方,在显示相关数据后,它还会显示为什么不能启动的错误所在.</p><p>&nbsp;</p><p>C:\Users\lenovo&gt;SQLPLUSSYS/SYS AS SYSDBA</p><p>SQL*Plus: Release 10.2.0.3.0 - Production on星期三 7月 3 11:43:32 2013</p><p>Copyright (c) 1982, 2006, Oracle.&nbsp; All Rights Reserved.</p><p>连接到:</p><p>Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -Production</p><p>With the Partitioning, OLAPand Data Mining options</p><p>SQL&gt; SHUTDOWN</p><p>ORA-01109:数据库未打开</p><p>已经卸载数据库。</p><p>ORACLE例程已经关闭。</p><p>SQL&gt; STARTUP</p><p>ORACLE例程已经启动。</p><p>Total System Global Area&nbsp;293601280 bytes</p><p>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1290208 bytes</p><p>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;234881056 bytes</p><p>Database Buffers&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50331648 bytes</p><p>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7098368 bytes</p><p>数据库装载完毕。</p><p>ORA-01157:无法标识/锁定数据文件 6 - 请参阅 DBWR 跟踪文件</p><p>ORA-01110:数据文件 6: 'F:\DC\DB\SDRS\TS_SDRS.DBF'</p><p>SQL&gt; alter databasedatafile'F:\DC\DB\SDRS\TS_SDRS.DBF'offline drop;</p><p>&nbsp;</p><p>数据库已更改。</p><p>&nbsp;</p><p>SQL&gt; alter database open;</p><p>&nbsp;</p><p>数据库已更改。</p><p>&nbsp;</p><p>SQL&gt; drop tablespaceTS_SDRS including contents;</p><p>&nbsp;</p><p>表空间已删除。</p><p>SQL&gt; create undo tablespace TS_SDRS</p><p>&nbsp; 2&nbsp; datafile'CracleoradatasmsdbUNDOTBS01.DBF'size 2048M extent management local;</p><p>&nbsp;</p><p>表空间已创建。</p><p>&nbsp;</p><p>SQL&gt; alter system setundo_tablespace=TS_SDRS;</p><p>&nbsp;</p><p>系统已更改。</p><p>&nbsp;</p><p>SQL&gt; shutdown</p><p>数据库已经关闭。</p><p>已经卸载数据库。</p><p>ORACLE例程已经关闭。</p><p>SQL&gt; startup</p><p>ORACLE例程已经启动。</p><p>&nbsp;</p><p>Total System Global Area&nbsp; 293601280 bytes</p><p>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1290208 bytes</p><p>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;243269664 bytes</p><p>Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;41943040 bytes</p><p>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7098368 bytes</p><p>数据库装载完毕。</p><p>数据库已经打开。</p><p>SQL&gt;</p><br />------------------<br /><a href="http://blog.itpub.net/22049049/viewspace-1029212/">ORA-01245、ORA-01547错误的解决</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em></em><br /><p>数据库rman restore database 之后，执行recover database的时候，报告ORA-01245错误，详细的错误信息如下： </p><p><table bgcolor="#999999"><tbody><tr><td><br />SQL&gt; recover database until cancel;<br />ORA-00279: change 575876 generated at 12/01/2009 08:19:49 needed for thread 1<br />ORA-00289: suggestion :<br />/oracle/flash_recovery_area/ORCL/archivelog/2009_12_01/o1_mf_1_2_%u_.arc<br />ORA-00280: change 575876 for thread 1 is in sequence #2<br /><br /><br />Specify log: {<ret>=suggested | filename | AUTO | CANCEL}<br />auto<br />ORA-00308: cannot open archived log<br />'/oracle/flash_recovery_area/ORCL/archivelog/2009_12_01/o1_mf_1_2_%u_.arc'<br />ORA-27037: unable to obtain file status<br />Linux Error: 2: No such file or directory<br />Additional information: 3<br /><br /><br />ORA-00308: cannot open archived log<br />'/oracle/flash_recovery_area/ORCL/archivelog/2009_12_01/o1_mf_1_2_%u_.arc'<br />ORA-27037: unable to obtain file status<br />Linux Error: 2: No such file or directory<br />Additional information: 3<br /><br /><br />ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below<br /><font color="#ff0000">ORA-01245: offline file 2 will be lost if RESETLOGS is done</font><br />ORA-01110: data file 2: '/oracle/oradata/orcl/undotbs01.dbf'<br /><br /><br />SQL&gt; </ret></td></tr></tbody></table><p>&nbsp;</p>[@more@]<p>检查ORA-01245那一行，发现是datafile 2状态为offline，解决的方法就是首先将datafile 2 online，然后再recover database。 </p><table bgcolor="#999999"><tbody><tr><td>SQL&gt; alter database datafile 2 online; <br /><br />Database altered. <br /><br />SQL&gt; recover database until cancel; <br />ORA-00279: change 575876 generated at 12/01/2009 08:19:49 needed for thread 1 <br />ORA-00289: suggestion : <br />/oracle/flash_recovery_area/ORCL/archivelog/2009_12_01/o1_mf_1_2_%u_.arc <br />ORA-00280: change 575876 for thread 1 is in sequence #2 <br /><br /><br />Specify log: {<ret>=suggested | filename | AUTO | CANCEL} <br />cancel <br />Media recovery cancelled. <br />SQL&gt; alter database open resetlogs; <br /><br />Database altered. <br /><br />SQL&gt;</ret></td></tr></tbody></table><br />--------------------<br /><h2 class="titName SG_txta" id="t_4ac959fa0100gyls">ORA-01589:&nbsp;要打开数据库则必须使用&nbsp;RESETLOGS&nbsp;或&nbsp;NOR</h2><br /><p><font style="font-size: 20px;">ORA-01589: 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS <br />选项<br /></font></p><br /><p>SQL&gt; alter database open&nbsp;<wbr><br />ORA-01589: 要打开数据库则必须使用 RESETLOGS 或 <br />NORESETLOGS 选项<br /><br />SQL&gt; alter database open resetlogs;<br />alter database <br />open resetlogs<br />*<br />ERROR 位于第 1 行:<br />ORA-01113: 文件 1 需要介质恢复<br />ORA-01110: <br />数据文件 1: 'E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF'<br /><br />SQL&gt; recover database <br />using backup controlfile;<br />ORA-00279: 更改 1670743 (在 04/17/2008 14:13:16 生成) <br />对于线程 1 是必需的<br />ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00030.001<br />ORA-00280: <br />更改 1670743 对于线程 1 是按序列 # 30 进行的<br /><br />指定日志: {&lt;RET&gt;=suggested | filename | <br />AUTO | CANCEL}<br />E:\oracle\oradata\EYGLE\REDO01.LOG<br />ORA-00310: 存档日志包含序列 <br />29；要求序列 30<br />ORA-00334: 归档日志: <br />'E:\ORACLE\ORADATA\EYGLE\REDO01.LOG'<br /><br />SQL&gt; recover database using <br />backup controlfile;<br />ORA-00279: 更改 1670743 (在 04/17/2008 14:13:16 生成) 对于线程 1 <br />是必需的<br />ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00030.001<br />ORA-00280: 更改 <br />1670743 对于线程 1 是按序列 # 30 进行的<br /><br />指定日志: {&lt;RET&gt;=suggested | filename | <br />AUTO | <br />CANCEL}<br />E:\oracle\oradata\EYGLE\REDO02.LOG<br />已应用的日志。<br />完成介质恢复。<br />SQL&gt; <br />alter database open resetlogs;<br />数据库已更改。<br /><br /><br />OK,搞定了!<br /></p><img src ="http://www.blogjava.net/brock/aggbug/413091.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-04-30 14:38 <a href="http://www.blogjava.net/brock/archive/2014/04/30/413091.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>split函数的几个问题</title><link>http://www.blogjava.net/brock/archive/2014/04/28/412995.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Mon, 28 Apr 2014 02:15:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/04/28/412995.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/412995.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/04/28/412995.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/412995.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/412995.html</trackback:ping><description><![CDATA[<p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">首先来看问题,然后来看函数的定义,其实什么都在函数定义里面说明白了</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">1.正则表达式字符串问题</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">首先输入的regex是一个正则表达式,而不是一个普通的字符串,所以导致很多在正则表达式里面有特殊意义的比如 "." "|" "\" ,如果直接使用是不行的,另外一个方面我们输入的regex是以字符串形式传递的,对有些字符必须要转义,尤其是"\",下面请看例子</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">String[] aa = "aaa|bbb|ccc".split("|");//wrong<br />String[] aa = "aaa|bbb|ccc".split("\\|"); //<br /></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;String[] aa = "aaa*bbb*ccc".split("*");//wrong<br />&nbsp;String[] aa = "aaa|bbb|ccc".split("\\*");</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;String[] aa = "aaa*bbb*ccc".split(".");//wrong<br />&nbsp;String[] aa = "aaa|bbb|ccc".split("\\.");</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">String[] aa = "aaa\\bbb\\bccc".split("\\");//wrong</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">String[] aa = "aaa\\bbb\\bccc".split("<a>\\\\</a>");</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">2.数组长度的问题</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">String a = "";<br />String[] b = a.split(",");<br />b.length为 1；<br />*<br />String a = "c";<br />String[] b = a.split(",");<br />b.length为 1；<br />**<br />String a = "c,,,";<br />String[] b = a.split(",");<br />b.length为 1；<br />***<br />String a = "c,,c";<br />String[] b = a.split(",");<br />b.length为 3；<br />****<br />String a = ",";<br />String[] b = a.split(",");<br />b.length为 0；</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">其实只要添加一个参数即可,例如</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;"><span style="line-height: 1.5;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;"></span><span style="line-height: 1.5;"><span style="line-height: 1.5;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;">String&nbsp;str&nbsp;</span><span style="line-height: 1.5;">=</span>&nbsp;<span style="line-height: 1.5;">"</span><span style="line-height: 1.5;">abcdef,ghijk,lmno,pqrst,,,</span><span style="line-height: 1.5;">"</span><span style="line-height: 1.5;">;</span></span></span></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;"><span style="line-height: 1.5;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;"><span style="line-height: 1.5; color: #ff0000;">String[] array = str.split(",");</span></span><span style="line-height: 1.5;"><br /><span style="line-height: 1.5;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;">输出:abcdef,ghijk,lmno,pqrst,</span></span></span></span></span></span></span></span></span></span></span></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;"><span style="line-height: 1.5; color: red;"></span></span>&nbsp;</span></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5; color: red;"><span style="line-height: 1.5; color: #000000;"><span style="line-height: 1.5;">String&nbsp;str&nbsp;</span><span style="line-height: 1.5;">=</span>&nbsp;<span style="line-height: 1.5;">"</span><span style="line-height: 1.5;">abcdef,ghijk,lmno,pqrst,,,</span><span style="line-height: 1.5;">"</span><span style="line-height: 1.5;">;<br /><span style="line-height: 1.5; color: #ff0000;">String[]&nbsp;array&nbsp;</span></span><span style="line-height: 1.5; color: #ff0000;">=&nbsp;str.split(","</span><span style="line-height: 1.5;"><span style="line-height: 1.5; color: #ff0000;">,-1);</span></span></span></span></span></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;"><span style="line-height: 1.5; color: #000000;">输出:abcdef,ghijk,lmno,pqrst,,,,</span></p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">public String []&nbsp;<strong>split</strong>&nbsp;(String&nbsp; regex, int&nbsp;limit)&nbsp;</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">最后一个参数limit是影响返回数组的长度的</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">=========================请关注红色字体(括号内为注释)==========================================</p><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">public&nbsp;<a title="java.lang 中的类" href="http://man.ddvip.com/program/java_api_zh/java/lang/String.html" style="color: #1a8bc8; text-decoration: none;">String</a>[]&nbsp;<strong>split</strong>(<a title="java.lang 中的类" href="http://man.ddvip.com/program/java_api_zh/java/lang/String.html" style="color: #1a8bc8; text-decoration: none;">String</a>&nbsp;regex)</p><dl style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><dd>根据给定的<span style="line-height: 1.5; color: red;">正则表达式</span>的匹配来拆分此字符串。<p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">该方法的作用就像是使用给定的表达式和限制参数 0 来调用两参数&nbsp;<a href="http://man.ddvip.com/program/java_api_zh/java/lang/String.html#split%28java.lang.String,%20int%29" style="color: #1a8bc8; text-decoration: none;"><code>split</code></a>&nbsp;方法。因此，<span style="line-height: 1.5; color: red;">结果数组中不包括结尾空字符串(直接使用会造成数组大小问题)</span>。</p><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">例如，字符串&nbsp;<tt>"boo:and:foo"</tt>&nbsp;产生带有下面这些表达式的结果：</p><blockquote><table cellspacing="0" cellpadding="1" summary="Split examples showing regex and result" style="border-style: solid; border-color: silver; border-collapse: collapse;"><tbody><tr><th style="border: 1px solid silver; border-collapse: collapse; padding: 3px;">Regex</th><th style="border: 1px solid silver; border-collapse: collapse; padding: 3px;">结果</th></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">:</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "boo", "and", "foo" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">o</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px; width: 189px; height: 22px;"><tt>{ "b", "", ":and:f" }</tt></td></tr></tbody></table></blockquote><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">&nbsp;</p></dd><dd><dl></dl></dd><dd><dl><dt><strong>参数：</strong></dt><dd><code>regex</code>&nbsp;- 定界正则表达式</dd><dt><strong>返回：</strong></dt><dd>字符串数组，根据给定正则表达式的匹配来拆分此字符串，从而生成此数组。</dd></dl></dd></dl><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">public&nbsp;<a title="java.lang 中的类" href="http://man.ddvip.com/program/java_api_zh/java/lang/String.html" style="color: #1a8bc8; text-decoration: none;">String</a>[]&nbsp;<strong>split</strong>(<a title="java.lang 中的类" href="http://man.ddvip.com/program/java_api_zh/java/lang/String.html" style="color: #1a8bc8; text-decoration: none;">String</a>&nbsp;regex,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;limit)</p><dl style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff;"><dd>根据匹配给定的<a href="http://man.ddvip.com/program/java_api_zh/java/util/regex/Pattern.html#sum" style="color: #1a8bc8; text-decoration: none;">正则表达式</a>来拆分此字符串。<p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">此方法返回的数组包含此字符串的每个子字符串，这些子字符串由另一个匹配给定的表达式的子字符串终止或由字符串结束来终止。数组中的子字符串按它们在此字符串中的顺序排列。如果表达式不匹配输入的任何部分，则结果数组只具有一个元素，即此字符串。</p><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;"><tt><span style="line-height: 1.5; color: red;">limit</span></tt><span style="line-height: 1.5; color: red;">&nbsp;参数控制模式应用的次数，因此影响结果数组的长度</span>。<span style="line-height: 1.5; color: red;">如果该限制&nbsp;</span><em style="color: red;">n</em><span style="line-height: 1.5; color: red;">&nbsp;大于 0，则模式将被最多应用&nbsp;</span><em style="color: red;">n</em><span style="line-height: 1.5; color: red;">&nbsp;-&nbsp;1 次，数组的长度将不会大于&nbsp;</span><em style="color: red;">n</em>，而且数组的最后项将包含超出最后匹配的定界符的所有输入。<span style="line-height: 1.5; color: red;">如果&nbsp;</span><em style="color: red;">n</em><span style="line-height: 1.5; color: red;">&nbsp;为非正，则模式将被应用尽可能多的次数</span>，而且数组可以是任意长度。<span style="line-height: 1.5; color: red;">如果&nbsp;</span><em style="color: red;">n</em><span style="line-height: 1.5; color: red;">&nbsp;为零，则模式将被应用尽可能多的次数，数组可有任何长度，并且结尾空字符串将被丢弃</span>。</p><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">例如，字符串&nbsp;<tt>"boo:and:foo"</tt>&nbsp;使用这些参数可生成下列结果：</p><blockquote><table cellspacing="0" cellpadding="1" summary="Split example showing regex, limit, and result" style="border-style: solid; border-color: silver; border-collapse: collapse;"><tbody><tr><th style="border: 1px solid silver; border-collapse: collapse; padding: 3px;">Regex</th><th style="border: 1px solid silver; border-collapse: collapse; padding: 3px;">Limit</th><th style="border: 1px solid silver; border-collapse: collapse; padding: 3px;">结果</th></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">:</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">2</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "boo", "and:foo" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">:</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">5</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "boo", "and", "foo" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">:</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">-2</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "boo", "and", "foo" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">o</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">5</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">o</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">-2</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr><tr><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">o</td><td align="center" style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;">0</td><td style="font-size: 12px; color: #454545; border-style: solid; border-color: silver; border-collapse: collapse; padding: 3px;"><tt>{ "b", "", ":and:f" }</tt></td></tr></tbody></table></blockquote><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">这种形式的方法调用&nbsp;<em>str.</em><tt>split(</tt><em>regex</em><tt>,</tt>&nbsp;<em>n</em><tt>)</tt>&nbsp;产生与以下表达式完全相同的结果：</p><blockquote><a title="java.util.regex 中的类" href="http://man.ddvip.com/program/java_api_zh/java/util/regex/Pattern.html" style="color: #1a8bc8; text-decoration: none;"><code>Pattern</code></a>.<a href="http://man.ddvip.com/program/java_api_zh/java/util/regex/Pattern.html#compile%28java.lang.String%29" style="color: #1a8bc8; text-decoration: none;"><code>compile</code></a><tt>(</tt><em>regex</em><tt>)</tt>.<a href="http://man.ddvip.com/program/java_api_zh/java/util/regex/Pattern.html#split%28java.lang.CharSequence,%20int%29" style="color: #1a8bc8; text-decoration: none;"><code>split</code></a><tt>(</tt><em>str</em><tt>,</tt>&nbsp;<em>n</em><tt>)</tt></blockquote><p style="line-height: 1.5; margin-top: 10px; margin-bottom: 10px;">&nbsp;</p></dd><dd><dl></dl></dd><dd><dl><dt><strong>参数：</strong></dt><dd><code>regex</code>&nbsp;- 定界正则表达式</dd><dd><code>limit</code>&nbsp;- 结果阈值，如上所述</dd><dt><strong>返回：</strong></dt><dd>字符串数组，根据给定正则表达式的匹配来拆分此字符串，从而生成此数组</dd></dl></dd></dl><p style="line-height: 19px; margin-top: 10px; margin-bottom: 10px; color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff;">&nbsp;</p><img src ="http://www.blogjava.net/brock/aggbug/412995.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-04-28 10:15 <a href="http://www.blogjava.net/brock/archive/2014/04/28/412995.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Calendar.getInstance() 不要放在循环里  当心OutOfMemoryError: Java heap space</title><link>http://www.blogjava.net/brock/archive/2014/01/08/408673.html</link><dc:creator>brock</dc:creator><author>brock</author><pubDate>Wed, 08 Jan 2014 03:26:00 GMT</pubDate><guid>http://www.blogjava.net/brock/archive/2014/01/08/408673.html</guid><wfw:comment>http://www.blogjava.net/brock/comments/408673.html</wfw:comment><comments>http://www.blogjava.net/brock/archive/2014/01/08/408673.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/brock/comments/commentRss/408673.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/brock/services/trackbacks/408673.html</trackback:ping><description><![CDATA[<pre style="padding: 1em; border: 1px dashed #2f6fab; background-color: #f9f9f9; line-height: 1.1em;">  List&lt;Calendar&gt; l = new ArrayList&lt;Calendar&gt;(); <br />       while (true) {         <br />   l.add(Calendar.getInstance()); <br />           System.out.println(l.size());   <br />     }           <br />  605473   <br />     Exception in thread "main" java.lang.OutOfMemoryError: Java heap space   <br />         at java.util.Calendar.&lt;init&gt;(Unknown Source) <br />           at java.util.GregorianCalendar.&lt;init&gt;(Unknown Source)<br />            at java.util.Calendar.createCalendar(Unknown Source)<br />            at java.util.Calendar.getInstance(Unknown Source)<br />            at jodatestmemory.Main.main(Main.java:25)</pre><img src ="http://www.blogjava.net/brock/aggbug/408673.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/brock/" target="_blank">brock</a> 2014-01-08 11:26 <a href="http://www.blogjava.net/brock/archive/2014/01/08/408673.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>