<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>windy2coast</title>
    <description></description>
    <link>http://windy2coast.javaeye.com</link>
    <language>UTF-8</language>
    <copyright>Copyright 2003-2008, JavaEye.com</copyright>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <generator>JavaEye - 做最棒的软件开发交流社区</generator>
      <item>
        <title>Java 仿 dos copy</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/137683" style="color:red;">http://windy2coast.javaeye.com/blog/137683</a>&nbsp;
          发表时间: 2007年11月02日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <div class="code_title">java 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-j">
    <li class="alt"><span><span class="keyword">import</span><span>&nbsp;java.io.*&nbsp;; &nbsp;&nbsp;</span></span> </li>
    <li class=""><span>&nbsp;&nbsp;</span> </li>
    <li class="alt"><span></span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;Copy &nbsp;&nbsp;</span> </li>
    <li class=""><span>{ &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;main(String&nbsp;args[]) &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">if</span><span>(args.length!=</span><span class="number">2</span><span>) &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span class="string">&quot;请输入正确的格式的参数:&nbsp;(例如:java&nbsp;Copy&nbsp;d:\\\\input.txt&nbsp;d:\\\\output.txt&quot;</span><span>)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">else</span><span>&nbsp; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file1&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;File(args[</span><span class="number">0</span><span>])&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;file2&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;File(args[</span><span class="number">1</span><span>])&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copyFile(file1,file2)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;copyFile(File&nbsp;srcfile,File&nbsp;desfile) &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">byte</span><span>[]&nbsp;b&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;</span><span class="keyword">byte</span><span>[</span><span class="number">512</span><span>]&nbsp;;</span><span class="comment">//512可以改成其它大于零的适当整数值 </span><span>&nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;len&nbsp;=&nbsp;</span><span class="number">0</span><span>&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">try</span><span>&nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fis&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;FileInputStream(srcfile)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fos&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;FileOutputStream(desfile)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">while</span><span>((len=fis.read(b))!=-</span><span class="number">1</span><span>)</span><span class="comment">//循环以512字节拷贝,知道拷贝完. </span><span>&nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fos.write(b,</span><span class="number">0</span><span>,len)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fis.close()&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fos.close()&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">catch</span><span>(Exception&nbsp;e) &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(e)&nbsp;; &nbsp;&nbsp;</span> </li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;</span> </li>
    <li class=""><span>};&nbsp;&nbsp;</span> </li>
</ol>
</div>
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/137683#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Fri, 02 Nov 2007 20:26:36 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/137683</link>
        <guid>http://windy2coast.javaeye.com/blog/137683</guid>
      </item>
      <item>
        <title>工厂模式经典例子</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/137108" style="color:red;">http://windy2coast.javaeye.com/blog/137108</a>&nbsp;
          发表时间: 2007年10月31日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p><font face="Arial">package org.lxh.demo ;<br />
import java.io.* ;<br />
import java.util.* ;<br />
interface Fruit<br />
{<br />
&nbsp;// 生长<br />
&nbsp;public void grow() ;<br />
&nbsp;// 采摘<br />
&nbsp;public void pick() ;<br />
}<br />
class Apple implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;苹果在生长。。。 &quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘苹果。。。&quot;) ;<br />
&nbsp;}<br />
};<br />
class Orange implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;橘子在生长。。。 &quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘橘子。。。&quot;) ;<br />
&nbsp;}<br />
};<br />
class Cherry implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;樱桃在生长。。。 &quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘樱桃。。。&quot;) ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">class WaterMelon implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;西瓜在生长。。。&quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘西瓜。。。&quot;) ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">class Banana implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;香蕉在生长。。。 &quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘香蕉。。。&quot;) ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">class DD implements Fruit<br />
{<br />
&nbsp;public void grow()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;DD。。。 &quot;) ;<br />
&nbsp;}<br />
&nbsp;public void pick()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;摘DD。。。&quot;) ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">class Factory<br />
{<br />
&nbsp;public static Fruit getFruitInstance(String type)<br />
&nbsp;{<br />
&nbsp;&nbsp;Fruit f = null ;<br />
&nbsp;&nbsp;// 通过Class类完成<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;f = (Fruit)Class.forName(type).newInstance() ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(e) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return f ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">// 定义一个新类，此类可以从键盘输入数据<br />
class InputData<br />
{<br />
&nbsp;BufferedReader buf = null ;<br />
&nbsp;public InputData()<br />
&nbsp;{<br />
&nbsp;&nbsp;buf = new BufferedReader(new InputStreamReader(System.in)) ;<br />
&nbsp;}<br />
&nbsp;public String getString()<br />
&nbsp;{<br />
&nbsp;&nbsp;String str = null ;<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;str = buf.readLine() ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return str ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">class Init<br />
{<br />
&nbsp;public static Properties getPropertiesInit()<br />
&nbsp;{<br />
&nbsp;&nbsp;Properties p = new Properties() ;<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;p.loadFromXML(new FileInputStream(&quot;lxh.xml&quot;)) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return p ;<br />
&nbsp;}<br />
};</font></p>
<p><font face="Arial">public class FactoryDemo06<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Properties p = new Properties() ;<br />
&nbsp;&nbsp;p = Init.getPropertiesInit() ;<br />
&nbsp;&nbsp;System.out.println(p) ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;// 加入一个可以从键盘输入数据的类<br />
&nbsp;&nbsp;System.out.print(&quot;输入要使用的子类代码：&quot;) ;<br />
&nbsp;&nbsp;String code = new InputData().getString() ;<br />
&nbsp;&nbsp;System.out.println(p.getProperty(code)) ;<br />
&nbsp;&nbsp;Fruit f = Factory.getFruitInstance(p.getProperty(code)) ;<br />
&nbsp;&nbsp;if(f!=null)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;f.grow() ;<br />
&nbsp;&nbsp;&nbsp;f.pick() ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(&quot;没有发现这个类型。&quot;) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
};</font></p>
<p>&nbsp;</p>
<p>lxh.xml</p>
<p><font face="Arial">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />
&lt;!DOCTYPE properties SYSTEM &quot;http://java.sun.com/dtd/properties.dtd&quot;&gt;<br />
&lt;properties&gt;<br />
&lt;comment&gt;MLDN --&amp;gt; LXH&lt;/comment&gt;<br />
&lt;entry key=&quot;b&quot;&gt;org.lxh.demo.Banana&lt;/entry&gt;<br />
&lt;entry key=&quot;a&quot;&gt;org.lxh.demo.Apple&lt;/entry&gt;<br />
&lt;entry key=&quot;o&quot;&gt;org.lxh.demo.Orange&lt;/entry&gt;<br />
&lt;entry key=&quot;c&quot;&gt;org.lxh.demo.Cherry&lt;/entry&gt;<br />
&lt;entry key=&quot;d&quot;&gt;org.lxh.demo.DD&lt;/entry&gt;<br />
&lt;/properties&gt;<br />
</font></p>
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/137108#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Wed, 31 Oct 2007 21:28:35 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/137108</link>
        <guid>http://windy2coast.javaeye.com/blog/137108</guid>
      </item>
      <item>
        <title>笔记**************</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/137106" style="color:red;">http://windy2coast.javaeye.com/blog/137106</a>&nbsp;
          发表时间: 2007年10月31日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p><font face="Arial">环境变量C:\jdk1.5.0_04&nbsp;&nbsp; JDK安装路径<br />
JAVA_HOME&nbsp;&nbsp; C:\jdk1.5.0_04</font></p>
<p><font face="Arial">编辑系统变量<br />
变量明：&nbsp; Path<br />
变量值： C:\jdk1.5.0_04\bin</font></p>
<font face="Arial">
<p><br />
在编译Servlet时，有时会出现找不到servlet包的问题，真是因为servlet为jdk的扩展包，所以在使用时需要指定classpath，具体方法 －－ set classpath=%Tomcat%\common\lib\servlet.jar<br />
如果不指定classpath，可以采用如下方法：<br />
－－将C:\Tomcat 5.0\common\lib\servlet-api.jar&nbsp;&nbsp;&nbsp;&nbsp; servlet-api.jar&nbsp; 文件拷贝到JDK安装路径下的jre\lib\ext\下</p>
<p><br />
C:\Tomcat 5.0\conf\server.xml<br />
&lt;Context path='/test' docBase=&quot;d:\testWeb&quot; reloadable=&quot;true&quot;/&gt;</p>
<p><br />
//隐藏文件到web-inf中 /&nbsp; 设置初始化参数<br />
D:\testWeb\WEB-INF\WEB.XML<br />
&lt;!-- JSPC servlet mappings start --&gt;</p>
<p>&nbsp;&lt;servlet&gt;<br />
&nbsp;&nbsp;&lt;servlet-name&gt;mldn&lt;/servlet-name&gt;<br />
&nbsp;&nbsp;&lt;jsp-file&gt;/WEB-INF/sdemo.jsp&lt;/jsp-file&gt;<br />
&nbsp;&nbsp;&lt;init-param&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-name&gt;uname&lt;/param-name&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-value&gt;mldn&lt;/param-value&gt;<br />
&nbsp;&nbsp;&lt;/init-param&gt;<br />
&nbsp;&nbsp;&lt;init-param&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-name&gt;upass&lt;/param-name&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;param-value&gt;lxh&lt;/param-value&gt;<br />
&nbsp;&nbsp;&lt;/init-param&gt;<br />
&nbsp;&lt;/servlet&gt;<br />
&nbsp;&lt;servlet-mapping&gt;<br />
&nbsp;&nbsp;&lt;servlet-name&gt;mldn&lt;/servlet-name&gt;<br />
&nbsp;&nbsp;&lt;url-pattern&gt;/lxh&lt;/url-pattern&gt;<br />
&nbsp;&lt;/servlet-mapping&gt;</p>
<p>&lt;!-- JSPC servlet mappings end --&gt;</p>
<p><br />
//servlet通用格式<br />
package cn.mldn.lxh.servlet.SimpleServlet ;<br />
import java.io.* ;<br />
import javax.servlet.* ;<br />
import javax.servlet.http.* ;</p>
<p>public class SimpleServlet extends HttpServlet<br />
{<br />
&nbsp;public void init(ServletConfig config) throws ServletException<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;**Servlet 初始化 ...&quot;) ;<br />
&nbsp;}<br />
&nbsp;public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException<br />
&nbsp;{<br />
&nbsp;&nbsp;PrintWriter out = resp.getWriter() ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;html&gt;&quot;) ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;head&gt;&quot;) ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;title&gt;the first servlet&lt;/title&gt;&quot;) ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;/head&gt;&quot;) ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;body&gt;&quot;) ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;out.println(&quot;&lt;h1&gt;hello world&lt;/h1&gt;&quot;) ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;out.println(&quot;&lt;/body&gt;&quot;) ;<br />
&nbsp;&nbsp;out.println(&quot;&lt;/html&gt;&quot;) ;<br />
&nbsp;&nbsp;<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException<br />
&nbsp;{<br />
&nbsp;&nbsp;this.doPost(req,resp) ;<br />
&nbsp;&nbsp;<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;public void destroy()<br />
&nbsp;{<br />
&nbsp;&nbsp;System.out.println(&quot;**Servlet销毁 ...&quot;) ;<br />
&nbsp;}<br />
};<br />
//servlet配置<br />
&lt;servlet&gt;<br />
&nbsp;&lt;servlet-name&gt;simple&lt;/servlet-name&gt;<br />
&nbsp;&lt;servlet-class&gt;cn.mldn.lxh.servlet.SimpleServlet&lt;/servlet-class&gt;<br />
&lt;/servlet&gt;</p>
<p>&lt;servlet-mapping&gt;//多地址访问同一servlet<br />
&nbsp;&lt;servlet-name&gt;simple&lt;/servlet-name&gt;<br />
&nbsp;&lt;url-pattern&gt;/demo&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;servlet-mapping&gt;//多地址访问同一servlet<br />
&nbsp;&lt;servlet-name&gt;simple&lt;/servlet-name&gt;<br />
&nbsp;&lt;url-pattern&gt;/demo.fad&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;servlet-mapping&gt;//多地址访问同一servlet<br />
&nbsp;&lt;servlet-name&gt;simple&lt;/servlet-name&gt;<br />
&nbsp;&lt;url-pattern&gt;/dfa&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;<br />
&lt;servlet-mapping&gt;//多地址访问同一servlet<br />
&nbsp;&lt;servlet-name&gt;simple&lt;/servlet-name&gt;<br />
&nbsp;&lt;url-pattern&gt;/hello/*&lt;/url-pattern&gt;<br />
&lt;/servlet-mapping&gt;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&lt;%@ page contentType=&quot;text/html;charset=gb2312&quot;%&gt;</p>
<p>&lt;%@ page import=&quot;java.sql.*&quot;%&gt;<br />
&lt;%--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JDBC-ODBC 连接方式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --%&gt;<br />
&lt;%!<br />
&nbsp;&nbsp;//定义数据库驱动程序<br />
&nbsp;&nbsp;String DBDRIVER = &quot;sun.jdbc.odbc.JdbcOdbcDriver&quot; ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//定义数据库连接地址,用JDBC-ODBC 则格式 固定如下<br />
&nbsp;&nbsp;String DBURL = &quot;jdbc:odbc:mldn&quot; ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//定义数据连接对象，属于java.sql包中的接口<br />
&nbsp;&nbsp;Connection conn = null ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//定义Statement对象，用于操纵数据库<br />
&nbsp;&nbsp;Statement stmt = null ;<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//定义一个字符串变量，用于保存SQL语句<br />
&nbsp;&nbsp;String sql = null ;<br />
%&gt;</p>
<p>&lt;%<br />
&nbsp;&nbsp;//1、加载驱动程序<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class.forName(DBDRIVER) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//此处使用out.println是出于演示目的，在实际开发中所有的错误<br />
&nbsp;&nbsp;&nbsp;&nbsp;//消息绝对不可以用out.println打印，否则会存在安全问题<br />
&nbsp;&nbsp;&nbsp;&nbsp;out.println(&quot;数据库驱动程序加载失败！！！&quot;) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//2、连接数据库<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection(DBURL) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;out.println(&quot;数据库连接失败!!!&quot;) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//3、操纵数据库<br />
&nbsp;&nbsp;//通过Connection对象实例化Statement对象 <br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt = conn.createStatement() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;// 为sql变量赋值<br />
&nbsp;&nbsp;&nbsp;&nbsp;//sql = &quot;insert into person (name,password,age) values('lxh','zzzzzz','28')&quot; ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;sql = &quot;update person set name='李新华',password='mldn' where id='1'&quot; ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt.executeUpdate(sql) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;out.println(&quot;操作数据库失败!!!&quot;) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;//4、关闭数据库<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//关闭操作<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;//关闭连接<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;out.println(&quot;关闭数据库失败！！！&quot;) ;<br />
&nbsp;&nbsp;}<br />
%&gt;</p>
<p><br />
利用JDBC开发Web数据库一般步骤:<br />
装入JDBC驱动程序<br />
创建与数据库的连接<br />
创建语句对象----Statement / PrepareStatement<br />
利用语句对象执行SQL语句得到结果<br />
处理结果<br />
JDBC应用结束</p>
<p>&nbsp;<br />
JavaBean 打包&nbsp;&nbsp; javac &ndash;d . SimpleBean.java<br />
upload.htm<br />
&lt;jsp:useBean id=&quot;sb&quot; scope=&quot;page&quot; class=&quot;cn.mldn.lxh.SimpleBean&quot;/&gt;</p>
<p>&lt;form action=&quot;upload.jsp&quot; method=&quot;post&quot; ENCTYPE=&quot;multipart/form-data&quot;&gt;<br />
选择要上传的图片：&lt;input type=&quot;file&quot; name=&quot;pic&quot;&gt;<br />
&lt;input type=&quot;submit&quot; value=&quot;提交&quot;&gt;<br />
&lt;/form&gt;</p>
<p>upload.jsp<br />
&lt;jsp:useBean id=&quot;smart&quot; scope=&quot;page&quot; class=&quot;org.lxh.smart.SmartUpload&quot;/&gt;<br />
&lt;%<br />
&nbsp;// 1、上传初始化<br />
&nbsp;smart.initialize(pageContext) ;<br />
&nbsp;// 2、准备上传<br />
&nbsp;smart.upload() ;<br />
&nbsp;// 3、保存上传的文件<br />
&nbsp;// smart.save(&quot;/upload&quot;) ;<br />
&nbsp;String ext = smart.getFiles().getFile(0).getFileExt() ;<br />
%&gt;</p>
<p>&lt;%<br />
&nbsp;String name = smart.getRequest().getParameter(&quot;name&quot;) ;<br />
%&gt;<br />
&lt;%<br />
&nbsp;// 保存文件<br />
&nbsp;smart.getFiles().getFile(0).saveAs(&quot;/upload/&quot;+name+&quot;.&quot;+ext) ;<br />
%&gt;</p>
<p><br />
//使用JSP标签去调用JavaBean时必须有一个无参构造函数</p>
<p>//两种方法调用JavaBean 。 一种是import导入&nbsp; 另一种用jsp的标签指令&lt;jsp:useBean&nbsp; .../&gt;</p>
<p>//使用JAVABEAN自动设置内容时，一定要使参数名称与Bean中属性名称一致，这样通过Java的命名规范，可以达到统一。</p>
<p><br />
使用MyEclipse运行WEB程序有以下两种方法：<br />
1、直接通过MyEclipse在服务器上进行部署（了解即可）<br />
2、通过外接服务器的方式运行程序（推荐）<br />
修改conf/server.xml文件</p>
<p>&nbsp;</p>
<p>与jsp页面中服务器跳转指令&lt;jsp:forward page=&quot;mvcdemo.jsp&quot;/&gt;类似<br />
Servlet跳转到JSP的服务器端跳转的指令是：req.getRequestDispatcher(&quot;mvcdemo.jsp&quot;).forward(req,resp) ;</p>
<p>我们可以发现：<br />
使用MVC开发程序，代码稍微复杂<br />
JSP与JavaBean之间没有什么特别明显的直接关系<br />
而Servlet根据JavaBean返回的内容进行跳转</p>
<p>Servlet中最好只有以下几种代码：<br />
接收参数<br />
调用JavaBean<br />
进行跳转<br />
有一些简单的逻辑判断</p>
<p>&nbsp;</p>
<p>//表达式语句取集合中的值</p>
<p>&lt;%@page import=&quot;java.util.*&quot;%&gt;<br />
&lt;%--</p>
<p>--%&gt;</p>
<p>&lt;%<br />
&nbsp;&nbsp;List l = (List)request.getAttribute(&quot;all&quot;) ;<br />
&nbsp;&nbsp;Iterator iter = l.iterator() ;<br />
&nbsp;&nbsp;while(iter.hasNext())<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;pageContext.setAttribute(&quot;sim&quot;,iter.next()) ;<br />
%&gt;<br />
&lt;h1&gt;${sim.name}&lt;/h1&gt;</p>
<p>&lt;%<br />
}<br />
%&gt;</p>
<p>&nbsp;</p>
<p><br />
监听器<br />
一、对ServletContext监听<br />
1、ServletContextListener:对整个Servlet上下文监听（启动、销毁）<br />
2、ServletContextAttributeListener:对Servlet上下文属性的监听<br />
二、对Session监听<br />
对session的创建、销毁、属性操作<br />
1、HttpSessionListener: 对session整体状况的监听<br />
2、HttpSessionAttributeListener：对session的属性监听</p>
<p>Session如何失效<br />
1、session超时<br />
&nbsp;&nbsp; 需要在web.xml中进行设置<br />
&nbsp;&nbsp; &lt;session-config&gt;<br />
&nbsp;&lt;session-timeout&gt;1&lt;/session-timeout&gt;<br />
&nbsp;&nbsp; &lt;/session-config&gt;<br />
2、手工使session失效<br />
&nbsp;&nbsp; invalidate()：使session失效&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.invalidate()&nbsp; ;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>同步问题的解决</p>
<p>class Demo implements Runnable<br />
{<br />
&nbsp;private int ticket = 10 ;<br />
&nbsp;// 加入一个同步方法<br />
&nbsp;public synchronized void fun() <br />
&nbsp;{<br />
&nbsp;&nbsp;// 把需要同步的地方放在同步方法之中<br />
&nbsp;&nbsp;if(this.ticket&gt;0)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;try<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(100) ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;System.out.println(Thread.currentThread().getName()+&quot; --&gt; 卖票：&quot;+this.ticket--) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
&nbsp;public void run()<br />
&nbsp;{<br />
&nbsp;&nbsp;while(ticket&gt;0)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;this.fun() ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
};<br />
public class ThreadDemo14<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Demo d = new Demo() ;<br />
&nbsp;&nbsp;Thread t1 = new Thread(d,&quot;售票点 A&quot;) ;<br />
&nbsp;&nbsp;Thread t2 = new Thread(d,&quot;售票点 B&quot;) ;<br />
&nbsp;&nbsp;Thread t3 = new Thread(d,&quot;售票点 C&quot;) ;</p>
<p>&nbsp;&nbsp;t1.start() ;<br />
&nbsp;&nbsp;t2.start() ;<br />
&nbsp;&nbsp;t3.start() ;<br />
&nbsp;}<br />
};</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>死锁问题的解决<br />
class Person<br />
{<br />
&nbsp;// 两种情况：&nbsp;李兴华&nbsp; 作者<br />
&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;MLDN&nbsp;&nbsp;网站<br />
&nbsp;private String name = &quot;李兴华&quot; ;<br />
&nbsp;private String content = &quot;作者&quot; ;<br />
&nbsp;private boolean flag = false ;<br />
&nbsp;// 加入一个设置的同步方法<br />
&nbsp;public synchronized void set(String name,String content)<br />
&nbsp;{<br />
&nbsp;&nbsp;// 如果为绿灯则表示可以设置，否则等待：true<br />
&nbsp;&nbsp;// 值是假，则表示要等待不能去设置<br />
&nbsp;&nbsp;if(flag)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;try<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;wait() ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;this.name = name ;<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;Thread.sleep(100) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;this.content = content ;<br />
&nbsp;&nbsp;// 设置完成之后，要改变灯<br />
&nbsp;&nbsp;flag = true ;<br />
&nbsp;&nbsp;notifyAll() ;<br />
&nbsp;}<br />
&nbsp;public synchronized String get()<br />
&nbsp;{<br />
&nbsp;&nbsp;if(!flag)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;try<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;wait() ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;catch (Exception e)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;String str = this.name+&quot; --&gt; &quot;+this.content ;<br />
&nbsp;&nbsp;// 如果为红灯，则表示可以取，否则等待：false<br />
&nbsp;&nbsp;flag = false ;<br />
&nbsp;&nbsp;notifyAll() ;<br />
&nbsp;&nbsp;return str ;<br />
&nbsp;}<br />
};<br />
class Pro implements Runnable<br />
{<br />
&nbsp;private Person per = null ;<br />
&nbsp;public Pro(Person per)<br />
&nbsp;{<br />
&nbsp;&nbsp;this.per = per ;<br />
&nbsp;}<br />
&nbsp;public void run()<br />
&nbsp;{<br />
&nbsp;&nbsp;for(int i=0;i&lt;100;i++)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;if(i%2==0)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;per.set(&quot;MLDN&quot;,&quot;网站&quot;) ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;per.set(&quot;李兴华&quot;,&quot;作者&quot;) ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
};</p>
<p>class Cust implements Runnable<br />
{<br />
&nbsp;private Person per = null ;<br />
&nbsp;public Cust(Person per)<br />
&nbsp;{<br />
&nbsp;&nbsp;this.per = per ;<br />
&nbsp;}<br />
&nbsp;public void run()<br />
&nbsp;{<br />
&nbsp;&nbsp;for(int i=0;i&lt;100;i++)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(per.get()) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
} ;</p>
<p>public class ThreadDemo19<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Person per = new Person() ;<br />
&nbsp;&nbsp;Pro p = new Pro(per)&nbsp; ;<br />
&nbsp;&nbsp;Cust c = new Cust(per) ;</p>
<p>&nbsp;&nbsp;new Thread(p).start() ;<br />
&nbsp;&nbsp;new Thread(c).start() ;<br />
&nbsp;}<br />
};</p>
<p>&nbsp;</p>
<p><br />
// 建立一个Person类，把Person类的对象序列化<br />
import java.io.* ;</p>
<p>class Person implements Serializable<br />
{<br />
&nbsp;private String name ;<br />
&nbsp;private transient int age ;<br />
&nbsp;public Person(String name,int age)<br />
&nbsp;{<br />
&nbsp;&nbsp;this.name = name ;<br />
&nbsp;&nbsp;this.age = age ;<br />
&nbsp;}<br />
&nbsp;public String toString()<br />
&nbsp;{<br />
&nbsp;&nbsp;return &quot;姓名：&quot;+this.name+&quot;，年龄：&quot;+this.age ;<br />
&nbsp;}<br />
};<br />
public class IODemo26<br />
{<br />
&nbsp;public static void main(String args[]) throws Exception<br />
&nbsp;{<br />
&nbsp;&nbsp;Person per = new Person(&quot;李兴华&quot;,30) ;<br />
&nbsp;&nbsp;ser(per) ;<br />
&nbsp;&nbsp;System.out.println(dser()) ;<br />
&nbsp;}<br />
&nbsp;// 建立一个方法用于完成对象的序列化<br />
&nbsp;public static void ser(Person per) throws Exception<br />
&nbsp;{<br />
&nbsp;&nbsp;ObjectOutputStream oos = null ;<br />
&nbsp;&nbsp;oos = new ObjectOutputStream(new FileOutputStream(new File(&quot;f:\\lxh.txt&quot;))) ;<br />
&nbsp;&nbsp;oos.writeObject(per) ;<br />
&nbsp;&nbsp;oos.close() ;<br />
&nbsp;}<br />
&nbsp;// 反序列化<br />
&nbsp;public static Person dser() throws Exception<br />
&nbsp;{<br />
&nbsp;&nbsp;ObjectInputStream ois = null ;<br />
&nbsp;&nbsp;ois = new ObjectInputStream(new FileInputStream(new File(&quot;f:\\lxh.txt&quot;))) ;<br />
&nbsp;&nbsp;Object obj = ois.readObject() ;<br />
&nbsp;&nbsp;ois.close() ;<br />
&nbsp;&nbsp;return (Person)obj ;<br />
&nbsp;}<br />
};</p>
<p>&nbsp;</p>
<p><br />
仿dos copy程序</p>
<p>import java.io.* ;</p>
<p>public class Copy<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;if(args.length!=2)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(&quot;请输入正确的格式的参数: (例如:java Copy d:\\\\input.txt d:\\\\output.txt&quot;) ;<br />
&nbsp;&nbsp;&nbsp;return ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;else <br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;File file1 = new File(args[0]) ;<br />
&nbsp;&nbsp;&nbsp;File file2 = new File(args[1]) ;<br />
&nbsp;&nbsp;&nbsp;copyFile(file1,file2) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;public static void copyFile(File srcfile,File desfile)<br />
&nbsp;{<br />
&nbsp;&nbsp;byte[] b = new byte[512] ;//512可以改成其它大于零的适当整数值<br />
&nbsp;&nbsp;int len = 0 ;<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp; FileInputStream fis = new FileInputStream(srcfile) ;<br />
&nbsp;&nbsp;&nbsp; FileOutputStream fos = new FileOutputStream(desfile) ;<br />
&nbsp;&nbsp;&nbsp;while((len=fis.read(b))!=-1)//循环以512字节拷贝,知道拷贝完.<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;fos.write(b,0,len) ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;fis.close() ;<br />
&nbsp;&nbsp;&nbsp;fos.close() ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(e) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
};</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>类集<br />
Collection: Collection下存放的就是一个个对象,每次存放单个对象<br />
Maps: 每次存放一对值 key -&gt; value<br />
Iterator: 输出接口,只要是集合都要去使用iterator输出</p>
<p>Collection接口:在一般开发中为了清楚的表现处理数据的存放往往不直接使用Collection接口<br />
&nbsp;&nbsp;&nbsp; 子接口:List<br />
&nbsp;&nbsp;&nbsp; 子接口:Set<br />
List既然是一个接口,则使用必须依靠子类 -&gt; ArrayList<br />
&nbsp;&nbsp;&nbsp; 如果要使用List ,则格式为: List l = new ArrayList() ;<br />
如果去使用类集则在加入对象时最好只加入一种对象.<br />
如果希望可以一个个元素打印出来,可以有两种方法:<br />
1.使用for循环 , size()方法求出对象数组的长度<br />
for(int i=0;i&lt;all.size();i++)<br />
{<br />
&nbsp;System.out.println(all.get(i)) ;<br />
}<br />
2.实际开发中一般用Iterator输出<br />
&nbsp; 因为集合的长度不固定,所以iterator采用的方法是一个一个判断输出<br />
&nbsp; 如果有下一个元素,则执行,如果没有则不执行<br />
while(iter.hasNext())<br />
{<br />
&nbsp;Object obj = iter.next() ;<br />
&nbsp;System.out.println(obj) ;<br />
}</p>
<p>Collection 集合操作的主要方法<br />
&nbsp;向集合中加入数据: public boolean add(Object obj)<br />
&nbsp;从集合中删除数据: public boolean remove(Object obj) / public boolean remove(int index)<br />
&nbsp;为Iterator实例化: public Iterator iterator()<br />
&nbsp;取出元素的个数&nbsp; : public int size()</p>
<p>Set的基本使用与List一致,但是HashSet子类存放时是无序的(散列存放) <br />
Set与List第二个区别:<br />
&nbsp;List中的数据允许重复元素,重复元素保留下来<br />
&nbsp;Set中的数据不允许重复元素,重复元素被替换掉<br />
在Set中如果使用HashSet则属于散列的无序的存放,如果希望有序存放使用TreeSet子类</p>
<p><br />
Map的主要功能是作为查找使用,而不是作为输出使用<br />
存数据的方法:<br />
&nbsp;put(Object key,Object value)<br />
取内容: 根据 key 取<br />
&nbsp;Object get(Object key)<br />
Map 接口的对象不能直接使用Iterator输出<br />
&nbsp;如果非要使用Iterator输出Map接口对象的内容,必须使用以下的步骤:<br />
&nbsp;Map -&gt; Set -&gt; Iterator -&gt; Map Entry -&gt; key , value</p>
<p>分清楚以下几点:<br />
保存单个值的集合:Collection<br />
&nbsp;List: 允许有重复元素<br />
&nbsp;&nbsp;Arraylist: 同步处理,新的类,只能用Iterator输出<br />
&nbsp;&nbsp;Vector: 同步处理,旧的类,能用Iterator和Enumeration同时输出<br />
&nbsp;Set: 不允许有重复元素<br />
&nbsp;&nbsp;HashSet: 散列,无序<br />
&nbsp;&nbsp;TreeSet: 有序,按Comparable排序<br />
保存一对值: Map<br />
&nbsp;HashMap: 异步处理,新的类<br />
&nbsp;Hashtable: 同步处理,旧的类<br />
&nbsp;TreeMap: 按KEY进行排序的集合<br />
输出<br />
&nbsp;Iterator: 新的输出类,方法名称较短<br />
&nbsp;Enumeration: 新的输出类,方法名称较长</p>
<p>&nbsp;</p>
<p><br />
对象克隆(复制)实例:<br />
要完成克隆的类必须具备以下两种条件<br />
1.类必须实现Cloneable接口,表示可以被克隆<br />
2.类必须覆写Object类中的clone方法<br />
import java.util.* ;<br />
class Person implements Cloneable<br />
{<br />
&nbsp;private String name ;<br />
&nbsp;private int age ;<br />
&nbsp;public Person(String name,int age)<br />
&nbsp;{<br />
&nbsp;&nbsp;this.name = name ;<br />
&nbsp;&nbsp;this.age = age ;<br />
&nbsp;}<br />
&nbsp;public String toString()<br />
&nbsp;{<br />
&nbsp;&nbsp;return &quot;姓名: &quot;+this.name+&quot; 年龄:&quot;+this.age ;<br />
&nbsp;}<br />
&nbsp;public Object clone()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws CloneNotSupportedException<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return super.clone() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
};<br />
public class Demo01<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Person p1 = new Person(&quot;李新华&quot;,33) ;<br />
&nbsp;&nbsp;try<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;Person p2 = (Person)p1.clone() ;<br />
&nbsp;&nbsp;&nbsp;System.out.println(p2) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;catch(Exception e)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;}<br />
};</p>
<p>&nbsp;</p>
<p>比较器:Comparable<br />
Arrays类 -&gt; 专门用于数组排序的<br />
可以对任意数据类型排序<br />
例题: 给出一个Person类里面包含姓名、年龄、成绩，声明5个Person对象的对象数组，要求对数组<br />
中的内容进行排序，排序规则如下：<br />
&nbsp;按成绩进行排序，如果成绩一样，按年龄由高到低进行排序</p>
<p>import java.util.* ;<br />
class Person implements Comparable //对象比较的类必须实现Comparable接口<br />
{<br />
&nbsp;private String name ;<br />
&nbsp;private int age ;<br />
&nbsp;private float score ;<br />
&nbsp;public Person(String name,int age,float score)<br />
&nbsp;{<br />
&nbsp;&nbsp;this.name = name ;<br />
&nbsp;&nbsp;this.age = age ;<br />
&nbsp;&nbsp;this.score = score ;<br />
&nbsp;}<br />
&nbsp;public String toString()<br />
&nbsp;{<br />
&nbsp;&nbsp;return &quot;姓名：&quot;+this.name+&quot;年龄：&quot;+this.age+&quot;成绩：&quot;+this.score ;<br />
&nbsp;}<br />
&nbsp;// 覆写compareTo方法就是排序规则<br />
&nbsp;public int compareTo(Object obj)<br />
&nbsp;{<br />
&nbsp;&nbsp;Person per = (Person)obj ;<br />
&nbsp;&nbsp;if(per.score &gt; this.score)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;return 1 ;//成绩由高到底排列<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;else if(per.score &lt; this.score)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;return -1 ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;else <br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;if(per.age &gt; this.age)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 1 ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;else if(per.age &lt; this.age)<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return -1 ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0 ;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
};</p>
<p>public class Demo01<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Person[] p = new Person[5] ;<br />
&nbsp;&nbsp;p[0] = new Person(&quot;张三&quot;,23,99) ;<br />
&nbsp;&nbsp;p[1] = new Person(&quot;李四&quot;,19,99) ;<br />
&nbsp;&nbsp;p[2] = new Person(&quot;张三&quot;,23,77) ;<br />
&nbsp;&nbsp;p[3] = new Person(&quot;张三&quot;,18,88) ;<br />
&nbsp;&nbsp;p[4] = new Person(&quot;张三&quot;,21,78) ;<br />
&nbsp;&nbsp;Arrays.sort(p) ;<br />
&nbsp;&nbsp;for(int i=0;i&lt;p.length;i++)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(p[i]) ;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;}<br />
};<br />
比较器除了在Arrays类的排序外还可以用在TreeSet上，实际上TreeSet也需要比较器支持<br />
public class Demo01<br />
{<br />
&nbsp;public static void main(String args[])<br />
&nbsp;{<br />
&nbsp;&nbsp;Set&lt;Person&gt; s = new TreeSet&lt;Person&gt;() ;<br />
&nbsp;&nbsp;s.add(new Person(&quot;张三&quot;,23,99)) ;<br />
&nbsp;&nbsp;s.add(new Person(&quot;李四&quot;,19,99)) ;<br />
&nbsp;&nbsp;s.add(new Person(&quot;张三&quot;,23,77)) ;<br />
&nbsp;&nbsp;s.add(new Person(&quot;张三&quot;,18,88)) ;<br />
&nbsp;&nbsp;s.add(new Person(&quot;张三&quot;,21,78)) ;<br />
&nbsp;&nbsp;Iterator iter = s.iterator() ;<br />
&nbsp;&nbsp;while(iter.hasNext()) <br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;System.out.println(iter.next()) ;<br />
&nbsp;&nbsp;}&nbsp;<br />
&nbsp;}<br />
};</p>
<p>Class类<br />
类-&gt;对象<br />
我希望由对象能够知道其所属的类是哪个<br />
&nbsp;&nbsp;&nbsp;&nbsp; void printClassName(Object obj) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&quot;The class of &quot; + obj +<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot; is &quot; + obj.getClass().getName());<br />
&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p>Class能够动态为类实例化<br />
Class类本身没有任何构造方法<br />
import java.util.* ;<br />
public class AdvDemo08<br />
{<br />
&nbsp;public static void main(String args[]) throws Exception<br />
&nbsp;{<br />
&nbsp;&nbsp;// 通过代码验证<br />
&nbsp;&nbsp;List all = null ;</p>
<p>&nbsp;&nbsp;// all = new ArrayList() ;</p>
<p>&nbsp;&nbsp;// 根据字符串找到一个类<br />
&nbsp;&nbsp;Class c = Class.forName(&quot;java.util.ArrayList&quot;) ;<br />
&nbsp;&nbsp;all = (List)c.newInstance() ;</p>
<p>&nbsp;&nbsp;all.add(&quot;A&quot;) ;<br />
&nbsp;&nbsp;all.add(&quot;B&quot;) ;<br />
&nbsp;&nbsp;all.add(&quot;C&quot;) ;</p>
<p>&nbsp;&nbsp;System.out.println(all) ;<br />
&nbsp;}<br />
};</p>
<p>总结: JAVA中对象实例化的途径<br />
1. 直接用new: 代码比较直观,但是程序会出现耦合度<br />
2. 程序出现了接口,如果一个接口的子类直接通过new实例化会造成程序耦合,所以使用工厂进行解耦合操作<br />
3. 对象的克隆,将对象拷贝一份,但是此种方法需要在子类中覆写clone() <br />
4. Class类,通过Class类来实例化一个对象,通过字符串操作完成</p>
<p>关于Class类只需重点掌握实例化对象的操作</p>
</font>
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/137106#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Wed, 31 Oct 2007 21:26:31 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/137106</link>
        <guid>http://windy2coast.javaeye.com/blog/137106</guid>
      </item>
      <item>
        <title>Happy Tree Friends 全集</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/134870" style="color:red;">http://windy2coast.javaeye.com/blog/134870</a>&nbsp;
          发表时间: 2007年10月23日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <table style="TABLE-LAYOUT: fixed">
    <tbody>
        <tr>
            <td>
            <div class="cnt">
            <div class="cnt">
            <p><font color="#800080"></font></p>
            <div forimg="1" align="center"><a href="http://www.coolwindy.com/movies/happytreefriends/htf.gif" target="_blank"></a></div>
            <div class="tmpDiv"></div>
            <div forimg="1" align="center"><img class="blogimg" small="0" src="http://www.coolwindy.com/movies/happytreefriends/htf.gif" border="0" alt="" /></div>
            <div class="tmpDiv">
            <p><strong><font color="#009933"><span class="STYLE1">Happy Tree Friends 简介：</span><br />
            </font></strong><span class="STYLE3"><font color="#006633">这是一部够搞的Flash <br />
            主人公都是天真无邪，可爱无比的小动物<br />
            但都会遭受意外而快乐的归西&hellip;&hellip;<br />
            每集Flash都充斥着独特的血腥暴力幽默<br />
            谁看谁知道~（胆小勿入） </font></span></p>
            </div>
            <div class="tmpDiv"></div>
            <div class="tmpDiv"></div>
            <table cellspacing="0" align="center" cellpadding="0">
                <tbody>
                    <tr>
                        <td width="100"><font color="#339966">01 </font><a href="http://www.coolwindy.com/movies/happytreefriends/baya.htm" target="_self"><font color="#339966">拔牙</font></a></td>
                        <td width="100"><font color="#339966">02 </font><a href="http://www.coolwindy.com/movies/happytreefriends/banjibiaoyan.htm" target="_self"><font color="#339966">班级表演</font></a></td>
                        <td width="100"><font color="#339966">03 </font><a href="http://www.coolwindy.com/movies/happytreefriends/baolingqiu.htm" target="_self"><font color="#339966">保龄球</font></a></td>
                        <td width="100"><font color="#339966">04 </font><a href="http://www.coolwindy.com/movies/happytreefriends/bingqilin.htm" target="_self"><font color="#339966">冰淇淋</font></a></td>
                        <td width="100"><font color="#339966">05 </font><a href="http://www.coolwindy.com/movies/happytreefriends/chidengpao.htm" target="_self"><font color="#339966">吃灯泡</font></a></td>
                        <td width="100"><font color="#339966">06 </font><a href="http://www.coolwindy.com/movies/happytreefriends/chitang.htm" target="_self"><font color="#339966">池塘</font></a></td>
                        <td width="100"><font color="#339966">07 </font><a href="http://www.coolwindy.com/movies/happytreefriends/chaorenmianbao.htm" target="_self"><font color="#339966">超人面包</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">08 </font><a href="http://www.coolwindy.com/movies/happytreefriends/chuciyuehui.htm" target="_self"><font color="#339966">初次约会</font></a></td>
                        <td width="100"><font color="#339966">09 </font><a href="http://www.coolwindy.com/movies/happytreefriends/chucao.htm" target="_self"><font color="#339966">锄草</font></a></td>
                        <td width="100"><font color="#339966">10 </font><a href="http://www.coolwindy.com/movies/happytreefriends/datuanyuan.htm" target="_self"><font color="#339966">大团圆</font></a></td>
                        <td width="100"><font color="#339966">11 </font><a href="http://www.coolwindy.com/movies/happytreefriends/diaoyu.htm" target="_self"><font color="#339966">钓鱼</font></a></td>
                        <td width="100"><font color="#339966">12 </font><a href="http://www.coolwindy.com/movies/happytreefriends/dongwuyuan1.htm" target="_self"><font color="#339966">动物园1</font></a></td>
                        <td width="100"><font color="#339966">13 </font><a href="http://www.coolwindy.com/movies/happytreefriends/dongwuyuan2.htm" target="_self"><font color="#339966">动物园2</font></a></td>
                        <td width="100"><font color="#339966">14 </font><a href="http://www.coolwindy.com/movies/happytreefriends/duantui.htm" target="_self"><font color="#339966">断腿</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">15 </font><a href="http://www.coolwindy.com/movies/happytreefriends/famu.htm" target="_self"><font color="#339966">伐木</font></a></td>
                        <td width="100"><font color="#339966">16 </font><a href="http://www.coolwindy.com/movies/happytreefriends/fuziqiu.htm" target="_self"><font color="#339966">父子球</font></a></td>
                        <td width="100"><font color="#339966">17 </font><a href="http://www.coolwindy.com/movies/happytreefriends/fuzichuhai.htm" target="_self"><font color="#339966">父子出海</font></a></td>
                        <td width="100"><font color="#339966">18 </font><a href="http://www.coolwindy.com/movies/happytreefriends/gonglusangming.htm" target="_self"><font color="#339966">公路丧命</font></a></td>
                        <td width="100"><font color="#339966">19 </font><a href="http://www.coolwindy.com/movies/happytreefriends/guicheng.htm" target="_self"><font color="#339966">鬼城</font></a></td>
                        <td width="100"><font color="#339966">20 </font><a href="http://www.coolwindy.com/movies/happytreefriends/guoshanche1.htm" target="_self"><font color="#339966">过山车1</font></a></td>
                        <td width="100"><font color="#339966">21 </font><a href="http://www.coolwindy.com/movies/happytreefriends/guoshanche2.htm" target="_self"><font color="#339966">过山车2</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">22 </font><a href="http://www.coolwindy.com/movies/happytreefriends/haidaogouyan.htm" target="_self"><font color="#339966">海盗钩眼</font></a></td>
                        <td width="100"><font color="#339966">23 </font><a href="http://www.coolwindy.com/movies/happytreefriends/huhuashizhe.htm" target="_self"><font color="#339966">护花使者</font></a></td>
                        <td width="100"><font color="#339966">24 </font><a href="http://www.coolwindy.com/movies/happytreefriends/hthuaxue.htm" target="_self"><font color="#339966">滑雪</font></a></td>
                        <td width="100"><font color="#339966">25 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jiandie.htm" target="_self"><font color="#339966">间谍</font></a></td>
                        <td width="100"><font color="#339966">26 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jianfei1.htm" target="_self"><font color="#339966">减肥1</font></a></td>
                        <td width="100"><font color="#339966">27 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jianfei2.htm" target="_self"><font color="#339966">减肥2</font></a></td>
                        <td width="100"><font color="#339966">28 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jiaoyou1.htm" target="_self"><font color="#339966">郊游1</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">29 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jiaoyou2.htm" target="_self"><font color="#339966">郊游2</font></a></td>
                        <td width="100"><font color="#339966">30 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jiepi1.htm" target="_self"><font color="#339966">洁癖1</font></a></td>
                        <td width="100"><font color="#339966">31 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jiepi2.htm" target="_self"><font color="#339966">洁癖2</font></a></td>
                        <td width="100"><font color="#339966">32 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jingyu.htm" target="_self"><font color="#339966">鲸鱼</font></a></td>
                        <td width="100"><font color="#339966">33 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jingchaguojiang.htm" target="_self"><font color="#339966">警察果酱</font></a></td>
                        <td width="100"><font color="#339966">34 </font><a href="http://www.coolwindy.com/movies/happytreefriends/jingchasharen.htm" target="_self"><font color="#339966">警察杀人</font></a></td>
                        <td width="100"><font color="#339966">35 </font><a href="http://www.coolwindy.com/movies/happytreefriends/kandianying.htm" target="_self"><font color="#339966">看电影</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">36 </font><a href="http://www.coolwindy.com/movies/happytreefriends/ketou.htm" target="_self"><font color="#339966">刻头</font></a></td>
                        <td width="100"><font color="#339966">37 </font><a href="http://www.coolwindy.com/movies/happytreefriends/lianai.htm" target="_self"><font color="#339966">恋爱</font></a></td>
                        <td width="100"><font color="#339966">38 </font><a href="http://www.coolwindy.com/movies/happytreefriends/mayituxiang.htm" target="_self"><font color="#339966">蚂蚁屠象</font></a></td>
                        <td width="100"><font color="#339966">39 </font><a href="http://www.coolwindy.com/movies/happytreefriends/mangrenwanqiu.htm" target="_self"><font color="#339966">盲人玩球</font></a></td>
                        <td width="100"><font color="#339966">40 </font><a href="http://www.coolwindy.com/movies/happytreefriends/moshu.htm" target="_self"><font color="#339966">魔术</font></a></td>
                        <td width="100"><font color="#339966">41 </font><a href="http://www.coolwindy.com/movies/happytreefriends/natang.htm" target="_self"><font color="#339966">拿糖</font></a></td>
                        <td width="100"><font color="#339966">42 </font><a href="http://www.coolwindy.com/movies/happytreefriends/saiche.htm" target="_self"><font color="#339966">赛车</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">43 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shetoubing.htm" target="_self"><font color="#339966">舌头冰</font></a></td>
                        <td width="100"><font color="#339966">44 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shetou.htm" target="_self"><font color="#339966">舌头</font></a></td>
                        <td width="100"><font color="#339966">45 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shu.htm" target="_self"><font color="#339966">书</font></a></td>
                        <td width="100"><font color="#339966">46 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shujiazi.htm" target="_self"><font color="#339966">鼠夹子</font></a></td>
                        <td width="100"><font color="#339966">47 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shuishanghuati.htm" target="_self"><font color="#339966">水上滑梯</font></a></td>
                        <td width="100"><font color="#339966">48 </font><a href="http://www.coolwindy.com/movies/happytreefriends/shuizai.htm" target="_self"><font color="#339966">水灾</font></a></td>
                        <td width="100"><font color="#339966">49 </font><a href="http://www.coolwindy.com/movies/happytreefriends/taoxin.htm" target="_self"><font color="#339966">掏心</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">50 </font><a href="http://www.coolwindy.com/movies/happytreefriends/titou.htm" target="_self"><font color="#339966">剃头</font></a></td>
                        <td width="100"><font color="#339966">51 </font><a href="http://www.coolwindy.com/movies/happytreefriends/tiaowu.htm" target="_self"><font color="#339966">跳舞</font></a></td>
                        <td width="100"><font color="#339966">52 </font><a href="http://www.coolwindy.com/movies/happytreefriends/touchilengyin.htm" target="_self"><font color="#339966">偷吃冷饮</font></a></td>
                        <td width="100"><font color="#339966">53 </font><a href="http://www.coolwindy.com/movies/happytreefriends/touniu.htm" target="_self"><font color="#339966">偷牛</font></a></td>
                        <td width="100"><font color="#339966">54 </font><a href="http://www.coolwindy.com/movies/happytreefriends/tourou.htm" target="_self"><font color="#339966">偷肉</font></a></td>
                        <td width="100"><font color="#339966">55 </font><a href="http://www.coolwindy.com/movies/happytreefriends/xi.htm" target="_self"><font color="#339966">吸</font></a></td>
                        <td width="100"><font color="#339966">56 </font><a href="http://www.coolwindy.com/movies/happytreefriends/xinfangzi.htm" target="_self"><font color="#339966">新房子</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">57 </font><a href="http://www.coolwindy.com/movies/happytreefriends/xuanwo1.htm" target="_self"><font color="#339966">漩涡1</font></a></td>
                        <td width="100"><font color="#339966">58 </font><a href="http://www.coolwindy.com/movies/happytreefriends/xuanwo2.htm" target="_self"><font color="#339966">漩涡2</font></a></td>
                        <td width="100"><font color="#339966">59 </font><a href="http://www.coolwindy.com/movies/happytreefriends/xunbao.htm" target="_self"><font color="#339966">寻宝</font></a></td>
                        <td width="100"><font color="#339966">60 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yanjingtangguo.htm" target="_self"><font color="#339966">眼睛糖果</font></a></td>
                        <td width="100"><font color="#339966">61 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yangjingyinliao.htm" target="_self"><font color="#339966">眼睛饮料</font></a></td>
                        <td width="100"><font color="#339966">62 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yingxiong.htm" target="_self"><font color="#339966">英雄</font></a></td>
                        <td width="100"><font color="#339966">63 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yuanshiren.htm" target="_self"><font color="#339966">原始人</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">64 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yuanzu1.htm" target="_self"><font color="#339966">远足1</font></a></td>
                        <td width="100"><font color="#339966">65 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yuanzu2.htm" target="_self"><font color="#339966">远足2</font></a></td>
                        <td width="100"><font color="#339966">66 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yueyu.htm" target="_self"><font color="#339966">越狱</font></a></td>
                        <td width="100"><font color="#339966">67 </font><a href="http://www.coolwindy.com/movies/happytreefriends/yundou.htm" target="_self"><font color="#339966">熨斗</font></a></td>
                        <td width="100"><font color="#339966">68 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zhuan.htm" target="_self"><font color="#339966">转</font></a></td>
                        <td width="100"><font color="#339966">69 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zhuangshideng.htm" target="_self"><font color="#339966">装饰灯</font></a></td>
                        <td width="100"><font color="#339966">70 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zhuomicang.htm" target="_self"><font color="#339966">捉迷藏</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">71 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zuzhou1.htm" target="_self"><font color="#339966">诅咒1</font></a></td>
                        <td width="100"><font color="#339966">72 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zuzhou2.htm" target="_self"><font color="#339966">诅咒2</font></a></td>
                        <td width="100"><font color="#339966">73 </font><a href="http://www.coolwindy.com/article.asp?id=80" target="_blank"><font color="#339966">天宫</font></a></td>
                        <td width="100"><font color="#339966">74 </font><a href="http://www.coolwindy.com/movies/happytreefriends/emengtonghua.htm" target="_self"><font color="#339966">恶梦童话</font></a></td>
                        <td width="100"><font color="#339966">75 </font><a href="http://www.coolwindy.com/movies/happytreefriends/zhongguihuangqiuan.htm" target="_self"><font color="#339966">终归黄泉</font></a></td>
                        <td width="100"><font color="#339966">76 </font><a href="http://www.coolwindy.com/article.asp?id=89" target="_blank"><font color="#339966">换心手术</font></a></td>
                        <td width="100"><font color="#339966">77 </font><a href="http://www.coolwindy.com/article.asp?id=111" target="_blank"><font color="#339966">拯救</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">78 </font><a href="http://www.coolwindy.com/article.asp?id=101" target="_blank"><font color="#339966">视力</font></a></td>
                        <td width="100"><font color="#339966">79 </font><a href="http://www.coolwindy.com/article.asp?id=81" target="_blank"><font color="#339966">阿拉丁</font></a></td>
                        <td width="100"><font color="#339966">80 </font><a href="http://www.coolwindy.com/article.asp?id=92" target="_blank"><font color="#339966">巨型玉米</font></a></td>
                        <td width="100"><font color="#339966">81 </font><a href="http://www.coolwindy.com/article.asp?id=104" target="_blank"><font color="#339966">想回到过去</font></a></td>
                        <td width="100"><font color="#339966">82 </font><a href="http://www.coolwindy.com/article.asp?id=102" target="_blank"><font color="#339966">嗜糖如命</font></a></td>
                        <td width="100"><font color="#339966">83 </font><a href="http://www.coolwindy.com/article.asp?id=86" target="_blank"><font color="#339966">都怪混泥土</font></a></td>
                        <td width="100"><font color="#339966">84 </font><a href="http://www.coolwindy.com/article.asp?id=87" target="_blank"><font color="#339966">狗不可貌相</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">85 </font><a href="http://www.coolwindy.com/article.asp?id=109" target="_blank"><font color="#339966">战争狂想曲1</font></a></td>
                        <td width="100"><font color="#339966">86 </font><a href="http://www.coolwindy.com/article.asp?id=110" target="_blank"><font color="#339966">战争狂想曲2</font></a></td>
                        <td width="100"><font color="#339966">87 </font><a href="http://www.coolwindy.com/article.asp?id=103" target="_blank"><font color="#339966">误入巨人国</font></a></td>
                        <td width="100"><font color="#339966">88 </font><a href="http://www.coolwindy.com/article.asp?id=108" target="_blank"><font color="#339966">增发水</font></a></td>
                        <td width="100"><font color="#339966">89 </font><a href="http://www.coolwindy.com/article.asp?id=99" target="_blank"><font color="#339966">圣诞小偷</font></a></td>
                        <td width="100"><font color="#339966">90 </font><a href="http://www.coolwindy.com/article.asp?id=88" target="_blank"><font color="#339966">环保行动</font></a></td>
                        <td width="100"><font color="#339966">91 </font><a href="http://www.coolwindy.com/article.asp?id=85" target="_blank"><font color="#339966">放射宝石</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">92 </font><a href="http://www.coolwindy.com/article.asp?id=100" target="_blank"><font color="#339966">失聪</font></a></td>
                        <td width="100"><font color="#339966">93 </font><a href="http://www.coolwindy.com/article.asp?id=107" target="_blank"><font color="#339966">造房子</font></a></td>
                        <td width="100"><font color="#339966">94 </font><a href="http://www.coolwindy.com/article.asp?id=94" target="_blank"><font color="#339966">裂痕追杀</font></a></td>
                        <td width="100"><font color="#339966">95 </font><a href="http://www.coolwindy.com/article.asp?id=96" target="_blank"><font color="#339966">内科手术</font></a></td>
                        <td width="100"><font color="#339966">96 </font><a href="http://www.coolwindy.com/article.asp?id=91" target="_blank"><font color="#339966">家有宠物</font></a></td>
                        <td width="100"><font color="#339966">97 </font><a href="http://www.coolwindy.com/article.asp?id=95" target="_blank"><font color="#339966">明星梦</font></a></td>
                        <td width="100"><font color="#339966">98 </font><a href="http://www.coolwindy.com/article.asp?id=106" target="_blank"><font color="#339966">邮递员</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">99 </font><a href="http://www.coolwindy.com/article.asp?id=97" target="_blank"><font color="#339966">求职记</font></a></td>
                        <td width="100"><font color="#339966">100 </font><a href="http://www.coolwindy.com/article.asp?id=98" target="_blank"><font color="#339966">生日party</font></a></td>
                        <td width="100"><font color="#339966">101 </font><a href="http://www.coolwindy.com/article.asp?id=83" target="_blank"><font color="#339966">超人归来</font></a></td>
                        <td width="100"><font color="#339966">102 </font><a href="http://www.coolwindy.com/article.asp?id=82" target="_blank"><font color="#339966">冰国求生</font></a></td>
                        <td width="100"><font color="#339966">103 </font><a href="http://www.coolwindy.com/article.asp?id=105" target="_blank"><font color="#339966">蚁战</font></a></td>
                        <td width="100"><font color="#339966">104 </font><a href="http://www.coolwindy.com/article.asp?id=90" target="_blank"><font color="#339966">火灾</font></a></td>
                        <td width="100"><font color="#339966">105 </font><a href="http://www.coolwindy.com/article.asp?id=93" target="_blank"><font color="#339966">空难</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">106 </font><a href="http://www.coolwindy.com/article.asp?id=84" target="_blank"><font color="#339966">冲浪</font></a></td>
                        <td width="100"><span class="STYLE2"><font color="#339966">更新中......</font><a href="http://www.windycool.com/g2/rope.htm" target="_self"></a></span></td>
                        <td width="100"><font color="#339966"></font></td>
                        <td width="100"><font color="#339966"></font></td>
                        <td width="100"><font color="#339966"></font></td>
                        <td width="100"><font color="#339966"></font></td>
                        <td width="100"><font color="#339966"></font></td>
                    </tr>
                </tbody>
            </table>
            <p align="center"><span class="STYLE1"><strong><font color="#339966">Happy Tree Friends 游戏</font></strong></span></p>
            <table cellspacing="0" align="center" cellpadding="0">
                <tbody>
                    <tr>
                        <td width="100"><font color="#339966">01 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Cuddles.htm" target="_self"><font color="#339966">Cuddles</font></a></td>
                        <td width="100"><font color="#339966">02 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Flaky.htm" target="_self"><font color="#339966">Flaky</font></a></td>
                        <td width="100"><font color="#339966">03 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Giggles.htm" target="_self"><font color="#339966">Giggles</font></a></td>
                        <td width="100"><font color="#339966">04 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Nutty.htm" target="_self"><font color="#339966">Nutty</font></a></td>
                        <td width="100"><font color="#339966">05 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Petunia.htm" target="_self"><font color="#339966">Petunia</font></a></td>
                        <td width="100"><font color="#339966">06 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Pop.htm" target="_self"><font color="#339966">Pop</font></a></td>
                        <td width="100"><font color="#339966">07 </font><a href="http://www.coolwindy.com/movies/happytreefriends/sniffles.htm" target="_self"><font color="#339966">Sniffles</font></a></td>
                    </tr>
                    <tr>
                        <td width="100"><font color="#339966">01 </font><a href="http://www.coolwindy.com/movies/happytreefriends/Toothy.htm" target="_self"><font color="#339966">Toothy</font></a></td>
                        <td width="100"><span class="STYLE2"><font color="#339966">更新中......</font><a href="http://www.windycool.com/g2/rope.htm" target="_self"></a></span></td>
                        <td width="100"><font color="#339966"></font></td>
                        <td width="100"><font color="#339966"></font></td>
                    </tr>
                </tbody>
            </table>
            </div>
            </div>
            </td>
        </tr>
    </tbody>
</table>
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/134870#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Tue, 23 Oct 2007 18:43:12 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/134870</link>
        <guid>http://windy2coast.javaeye.com/blog/134870</guid>
      </item>
      <item>
        <title>div+css布局入门教程(三)</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/113106" style="color:red;">http://windy2coast.javaeye.com/blog/113106</a>&nbsp;
          发表时间: 2007年08月16日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          三、页面顶部制作(1)<br />
<br />
　　当我们写好了页面大致的DIV结构后，我们就可以开始细致地对每一个部分进行制作了。<br />
<br />
　　在上一章中我们写入了一些样式，那些样式是为了预览结构而写入的，我们把css.css中的样式全部清除掉，重新写入以下样式代码：<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent">/*基本信息*/<br />
body {font:12px Tahoma;margin:0px;text-align:center;background:#FFF;}<br />
a:link,a:visited <br />
a:hover{}<br />
<br />
/*页面层容器*/<br />
#container {width:800px;margin:10px auto}</div>
</div>
<br />
　　<em><strong>样式说明：</strong></em><br />
<br />
　　<em>a:link,a:visited <br />
　　a:hover {}</em><br />
<br />
　　这两项分别是控制页面中超链接的样式，具体我就不说明了，请大家参阅手册。<br />
<br />
　　<em>#container {width:800px;margin:10px auto}</em><br />
<br />
　　指定整个页面的显示区域。<br />
　　<em>width:800px</em>指定宽度为800像素，这里根据实际所需设定。<br />
　　<em>margin:10px auto</em>，则是页面上、下边距为10个像素，并且居中显示。<br />
　　上一章中我们讲过，<span style="COLOR: red">对层的margin属性的左右边距设置为auto可以让层居中显示</span>。<br />
<br />
　　接下来，我们开始制作TOP部分，TOP部分包括了<strong>LOGO</strong>、<strong>菜单</strong>和<strong>Banner</strong>，首先我们要做的就是对设计好的图片进行切片，以下是在FW下完成的切片：<br />
<img title="在新窗口打开图片" src="http://www.tblog.com.cn/attachments/month_0603/02006325141424.gif" border="0" alt="" style="CURSOR: pointer" /><br />
　　我将TOP部分切片为两部分，第一部分包括了LOGO和一条横线。由于LOGO图片并没有太多的颜色，这里我于是将这一部分保存为GIF格式，调色板选择为精确，选择Alpha透明度，色版为白色(此处颜色应与背景色相同)，导出为<em>logo.gif</em>，图像宽度为<em>800px</em>。<br />
<br />
　　到这里，有的朋友就说了，<strong>* 为什么要使用GIF格式？使用JPEG不是更好吗？</strong><br />
　　因为GIF格式的图片文件更小，这样能使页面载入的速度更快，当然使用此格式之前必须确定图片并没有使用太多的颜色，当我们使用了GIF格式时，从肉眼上并不能看出图片有什么太大的变化，因此这是可行的。<br />
<br />
　　<strong>* 接下来的Banner部分还能使用GIF格式吗？</strong><br />
　　答案是不能，因为Banner部分是一个细致的图片，如果使用GIF格式颜色会有太大的损失，所以必须使用JPEG格式，将文件导出为<em>banner.jpg</em>。<br />
<br />
　　<strong><span style="COLOR: red">* 合理的切片是非常之重要的，因为切片的方法正确与否决定了CSS书写的简易程度以及页面载入速度。</span></strong><br />
<br />
　　切好片后，我们还需要对TOP部分进行分析并将DIV结构写入Header中代码如下：<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent">　　&lt;div id=&quot;menu&quot;&gt;<br />
　　　&lt;ul&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;<br />
　　　　&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;博客&lt;/a&gt;&lt;/li&gt;<br />
　　　　&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;设计&lt;/a&gt;&lt;/li&gt;<br />
　　　　&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;相册&lt;/a&gt;&lt;/li&gt;<br />
　　　　&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;论坛&lt;/a&gt;&lt;/li&gt;<br />
　　　　&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;<br />
　　　　&lt;li&gt;&lt;a href=&quot;#&quot;&gt;关于&lt;/a&gt;&lt;/li&gt;<br />
　　　&lt;/ul&gt;<br />
　　&lt;/div&gt;<br />
　　&lt;div id=&quot;banner&quot;&gt;<br />
　　&lt;/div&gt;</div>
</div>
<br />
　　为什么要这么写呢，因为对菜单使用列表<em><strong>&lt;li&gt;</strong></em>形式，可以在以后方便对菜单定制样式。<br />
<br />
　　而为什么要添加以下代码呢？<br />
　　<em>&lt;li class=&quot;menuDiv&quot;&gt;&lt;/li&gt;</em><br />
　　插入这一段代码是可以方便地对菜单选项之间插入一些分隔样式，例如预览图中的<strong>竖线分隔</strong>。<br />
<br />
　　然后我们在css.css中再写入以下样式：<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent">/*页面头部*/<br />
#header {background:url(logo.gif) no-repeat}</div>
</div>
<br />
　　<em><strong>样式说明：</strong></em><br />
　　<em>#header {background:url(logo.gif) no-repeat}</em><br />
　　给页面头部分加入一个背景图片LOGO，并且不作填充。<br />
<br />
　　<strong>这里，我们没有指定header层的高度，为什么不指定呢？</strong><br />
<br />
　　因为header层中还有菜单和banner项，所以层的高度暂时是未知的，而层的属性又可以让层根据内容自动设定调整，因此我们并不需要指定高度。<br />
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/113106#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Thu, 16 Aug 2007 19:30:40 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/113106</link>
        <guid>http://windy2coast.javaeye.com/blog/113106</guid>
      </item>
      <item>
        <title>div+css布局入门教程(二)</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/113105" style="color:red;">http://windy2coast.javaeye.com/blog/113105</a>&nbsp;
          发表时间: 2007年08月16日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          二、写入整体层结构与CSS<br />
<br />
　　接下来我们在桌面新建一个文件夹，命名为&ldquo;DIV+CSS布局练习&rdquo;，在文件夹下新建两个空的记事本文档，输入以下内容：<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;<br />
&lt;title&gt;无标题文档&lt;/title&gt;<br />
&lt;link href=&quot;css.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;<br />
&lt;/head&gt;<br />
<br />
&lt;body&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</div>
</div>
<br />
　　这是XHTML的基本结构，将其命名为index.htm，另一个记事本文档则命名为css.css。<br />
<br />
　　下面，我们在&lt;body&gt;&lt;/body&gt;标签对中写入DIV的基本结构，代码如下：<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent"><br />
&lt;div id=&quot;container&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--页面层容器--&gt;</span><br />
　　&lt;div id=&quot;Header&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--页面头部--&gt;</span><br />
　　&lt;/div&gt;<br />
　　&lt;div id=&quot;PageBody&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--页面主体--&gt;</span><br />
　　　　&lt;div id=&quot;Sidebar&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--侧边栏--&gt;</span><br />
　　　　&lt;/div&gt;<br />
　　　　&lt;div id=&quot;MainBody&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--主体内容--&gt;</span><br />
　　　　&lt;/div&gt;<br />
　　&lt;/div&gt;<br />
　　&lt;div id=&quot;Footer&quot;&gt;<span style="COLOR: rgb(170,170,170)">&lt;!--页面底部--&gt;</span><br />
　　&lt;/div&gt;<br />
&lt;/div&gt;<br />
</div>
</div>
<br />
　　为了使以后阅读代码更简易，我们应该添加相关注释，接下来打开css.css文件，写入CSS信息，代码如下：<br />
<br />
<div class="UBBPanel">
<div class="UBBTitle">&nbsp;程序代码</div>
<div class="UBBContent"><br />
/*基本信息*/<br />
body {font:12px Tahoma;margin:0px;text-align:center;background:#FFF;}<br />
<br />
/*页面层容器*/<br />
#container <br />
<br />
/*页面头部*/<br />
#Header {width:800px;margin:0 auto;height:100px;background:#FFCC99}<br />
<br />
/*页面主体*/<br />
#PageBody {width:800px;margin:0 auto;height:400px;background:#CCFF00}<br />
<br />
/*页面底部*/<br />
#Footer {width:800px;margin:0 auto;height:50px;background:#00FFFF}<br />
</div>
</div>
<br />
　　把以上文件保存，用浏览器打开，这时我们已经可以看到基础结构了，这个就是页面的框架了。<br />
　　关于以上CSS的说明（详细请参考CSS2.0中文手册，网上有下载）：<br />
<br />
　　1、请养成良好的注释习惯，这是非常重要的；<br />
<br />
　　2、body是一个HTML元素，页面中所有的内容都应该写在这标签对之内，我就不多说了；<br />
<br />
　　3、讲解一些常用的CSS代码的含义：<br />
<br />
　　　　<strong>font:12px Tahoma；</strong><br />
　　　　这里使用了缩写，完整的代码应该是：font-size:12px;font-family:Tahoma；说明字体为12像素大小，字体为Tahoma格式；<br />
<br />
　　　　<strong>margin:0px；</strong><br />
　　　　也使用了缩写，完整的应该是：<br />
<br />
　　　　<em>margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px</em><br />
　　　　或<br />
　　　　<em>margin:0px 0px 0px 0px</em><br />
<br />
　　　　顺序是 上 / 右 / 下 / 左，你也可以书写为margin:0(缩写)；<br />
　　　　以上样式说明body部分对上右下左边距为0像素，如果使用auto则是自动调整边距，<br />
　　　　另外还有以下几种写法：<br />
　　　　<em>margin:0px auto；</em><br />
　　　　说明上下边距为0px，左右为自动调整；<br />
　　　　我们以后将使用到的padding属性和margin有许多相似之处，他们的参数是一样的，<br />
　　　　只不过各自表示的含义不相同，margin是外部距离，而padding则是内部距离。<br />
<br />
　　　　<strong>text-align:center</strong><br />
　　　　文字对齐方式，可以设置为左、右、中，这里我将它设置为居中对齐。<br />
<br />
　　　　<strong>background:#FFF</strong><br />
　　　　设置背景色为白色，这里颜色使用了缩写，完整的应该是background:#FFFFFF。<br />
　　　　background可以用来给指定的层填充背景色、背景图片，以后我们将用到如下格式：<br />
　　　　<em>background:#ccc url('bg.gif') top left no-repeat；</em><br />
　　　　表示：使用#CCC(灰度色)填充整个层，使用bg.gif做为背景图片，<br />
　　　　<em>top left</em><br />
　　　　表示图片位于当前层的左上端，no-repeat表示仅显示图片大小而不填充满整个层。<br />
　　　　<em>top/right/left/bottom/center</em><br />
　　　　用于定位背景图片，分别表示 上 / 右 / 下 / 左 / 中；还可以使用<br />
　　　　<em>background:url('bg.gif') 20px 100px;</em><br />
　　　　表示X座标为20像素，Y座标为100像素的精确定位；<br />
　　　　<em>repeat/no-repeat/repeat-x/repeat-y</em><br />
　　　　分别表示 填充满整个层 / 不填充 / 沿X轴填充 / 沿Y轴填充。<br />
<br />
　　　　<strong>height / width / color</strong> <br />
　　　　分别表示高度(px)、宽度(px)、字体颜色(HTML色系表)。<br />
<br />
　　4、如何使页面居中？<br />
　　　　大家将代码保存后可以看到，整个页面是居中显示的，那么究竟是什么原因使得页面居中显示呢？<br />
　　　　是因为我们在#container中使用了以下属性：<br />
　　　　<em>margin:0 auto;</em><br />
　　　　按照前面的说明，可以知道，表示上下边距为0，左右为自动，因此该层就会自动居中了。<br />
　　　　如果要让页面居左，则取消掉auto值就可以了，因为默认就是居左显示的。<br />
　　　　通过<em>margin:auto</em>我们就可以轻易地使层自动居中了。<br />
<br />
　　5、这里我只介绍这些常用的CSS属性了，其他的请参看CSS2.0中文手册。
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/113105#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Thu, 16 Aug 2007 19:29:55 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/113105</link>
        <guid>http://windy2coast.javaeye.com/blog/113105</guid>
      </item>
      <item>
        <title>div+css布局入门教程(一)</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/113104" style="color:red;">http://windy2coast.javaeye.com/blog/113104</a>&nbsp;
          发表时间: 2007年08月16日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          由于最近想使用div+css制作网站,在网络上找到这篇div+css的入门教程,觉得非常浅显易懂,对自己的div+css网站布局的学习很有帮助,于是转贴过来<br />
<br />
一、页面布局与规划<br />
<br />
　　好久没有认真写点东西了，想起最近这些时间经常有朋友问到我有关于DIV+CSS布局的问题，其实归根结底还是由于没有入门造成的。那么接下来的这篇文章就带领大家入门吧...<br />
<br />
　 　在网页制作中，有许多的术语，例如：CSS、HTML、DHTML、XHTML等等。在下面的文章中我们将会用到一些有关于HTML的基本知识，而在你 学习这篇入门教程之前，请确定你已经具有了一定的HTML基础。下面我们就开始一步一步使用DIV+CSS进行网页布局设计吧。<br />
<br />
　　所有的设计第一步就是构思，构思好了，一般来说还需要用PhotoShop或FireWorks(以下简称PS或FW)等图片处理软件将需要制作的界面布局简单的构画出来，以下是我构思好的界面布局图。<br />
<br />
<img title="在新窗口打开图片" src="http://www.tblog.com.cn/attachments/month_0603/w2006318142229.jpg" border="0" alt="" style="CURSOR: pointer" /><br />
<br />
　　下面，我们需要根据构思图来规划一下页面的布局，仔细分析一下该图，我们不难发现，图片大致分为以下几个部分：<br />
　　1、顶部部分，其中又包括了LOGO、MENU和一幅Banner图片；<br />
　　2、内容部分又可分为侧边栏、主体内容；<br />
　　3、底部，包括一些版权信息。<br />
　　有了以上的分析，我们就可以很容易的布局了，我们设计层如下图：<br />
<img title="在新窗口打开图片" src="http://www.tblog.com.cn/attachments/month_0603/72006318142329.jpg" border="0" alt="" style="CURSOR: pointer" /><br />
<br />
　　根据上图，我再画了一个实际的页面布局图，说明一下层的嵌套关系，这样理解起来就会更简单了。<br />
<br />
<img src="http://www.tblog.com.cn/attachments/month_0603/j200631814242.gif" border="0" alt="" /><br />
　　DIV结构如下：<br />
　　│body {}　/*这是一个HTML元素，具体我就不说明了*/<br />
　　└#Container {}　/*页面层容器*/<br />
　　　　　├#Header {}　/*页面头部*/<br />
　　　　　├#PageBody {}　/*页面主体*/<br />
　　　　　│　├#Sidebar {}　/*侧边栏*/<br />
　　　　　│　└#MainBody {}　/*主体内容*/<br />
　　　　　└#Footer {}　/*页面底部*/<br />
　　至此，页面布局与规划已经完成，接下来我们要做的就是开始书写HTML代码和CSS。<br />
          <br/>
          <span style="color:red;">
            <a href="http://windy2coast.javaeye.com/blog/113104#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Thu, 16 Aug 2007 19:29:05 +0800</pubDate>
        <link>http://windy2coast.javaeye.com/blog/113104</link>
        <guid>http://windy2coast.javaeye.com/blog/113104</guid>
      </item>
      <item>
        <title>thinkinjava一系列项目</title>
        <author>windy2coast</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://windy2coast.javaeye.com">windy2coast</a>&nbsp;
          链接：<a href="http://windy2coast.javaeye.com/blog/112519" style="color:red;">http://windy2coast.javaeye.com/blog/112519</a>&nbsp;
          发表时间: 2007年08月15日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          本章包含了一系列项目，它们都以本书介绍的内容为基础，并对早期的章节进行了一定程度的扩充。<br />
与以前经历过的项目相比，这儿的大多数项目都明显要复杂得多，它们充分演示了新技术以及类库的运用。<br />
<br />
17.1 文字处理<br />
如果您有C或C++的经验，那么最开始可能会对Java控制文本的能力感到怀疑。事实上，我们最害怕的就是速度特别慢，这可能妨碍我们创造能力的发挥。然而，Java对应的工具（特别是String类）具有很强的功能，就象本节的例子展示的那样（而且性能也有一定程度的提升）。<br />
正如大家即将看到的那样，建立这些例子的目的都是为了解决本书编制过程中遇到的一些问题。但是，它们的能力并非仅止于此。通过简单的改造，即可让它们在其他场合大显身手。除此以外，它们还揭示出了本书以前没有强调过的一项Java特性。<br />
<br />
17.1.1 提取代码列表<br />
对于本书每一个完整的代码列表（不是代码段），大家无疑会注意到它们都用特殊的注释记号起始与结束（'//:'和'///:~'）。之所以要包括这种标志信息，是为了能将代码从本书自动提取到兼容的源码文件中。在我的前一本书里，我设计了一个系统，可将测试过的代码文件自动合并到书中。但对于这本书，我发现一种更简便的做法是一旦通过了最初的测试，就把代码粘贴到书中。而且由于很难第一次就编译通过，所以我在书的内部编辑代码。但如何提取并测试代码呢？这个程序就是关键。如果你打算解决一个文字处理的问题，那么它也很有利用价值。该例也演示了String类的许多特性。<br />
我首先将整本书都以ASCII文本格式保存成一个独立的文件。CodePackager程序有两种运行模式（在usageString有相应的描述）：如果使用-p标志，程序就会检查一个包含了ASCII文本（即本书的内容）的一个输入文件。它会遍历这个文件，按照注释记号提取出代码，并用位于第一行的文件名来决定创建文件使用什么名字。除此以外，在需要将文件置入一个特殊目录的时候，它还会检查package语句（根据由package语句指定的路径选择）。<br />
但这样还不够。程序还要对包（package）名进行跟踪，从而监视章内发生的变化。由于每一章使用的所有包都以c02，c03，c04等等起头，用于标记它们所属的是哪一章（除那些以com起头的以外，它们在对不同的章进行跟踪的时候会被忽略）&mdash;&mdash;只要每一章的第一个代码列表包含了一个package，所以CodePackager程序能知道每一章发生的变化，并将后续的文件放到新的子目录里。<br />
每个文件提取出来时，都会置入一个SourceCodeFile对象，随后再将那个对象置入一个集合（后面还会详尽讲述这个过程）。这些SourceCodeFile对象可以简单地保存在文件中，那正是本项目的第二个用途。如果直接调用CodePackager，不添加-p标志，它就会将一个&ldquo;打包&rdquo;文件作为输入。那个文件随后会被提取（释放）进入单独的文件。所以-p标志的意思就是提取出来的文件已被&ldquo;打包&rdquo;（packed）进入这个单一的文件。<br />
但为什么还要如此麻烦地使用打包文件呢？这是由于不同的计算机平台用不同的方式在文件里保存文本信息。其中最大的问题是换行字符的表示方法；当然，还有可能存在另一些问题。然而，Java有一种特殊类型的IO数据流&mdash;&mdash;DataOutputStream&mdash;&mdash;它可以保证&ldquo;无论数据来自何种机器，只要使用一个DataInputStream收取这些数据，就可用本机正确的格式保存它们&rdquo;。也就是说，Java负责控制与不同平台有关的所有细节，而这正是Java最具魅力的一点。所以-p标志能将所有东西都保存到单一的文件里，并采用通用的格式。用户可从Web下载这个文件以及Java程序，然后对这个文件运行CodePackager，同时不指定-p标志，文件便会释放到系统中正确的场所（亦可指定另一个子目录；否则就在当前目录创建子目录）。为确保不会留下与特定平台有关的格式，凡是需要描述一个文件或路径的时候，我们就使用File对象。除此以外，还有一项特别的安全措施：在每个子目录里都放入一个空文件；那个文件的名字指出在那个子目录里应找到多少个文件。<br />
下面是完整的代码，后面会对它进行详细的说明：<br />
<br />
<blockquote><font size="+1">
<pre><font color="#009900">//: CodePackager.java</font>
<font color="#009900">// &quot;Packs&quot; and &quot;unpacks&quot; the code in &quot;Thinking </font>
<font color="#009900">// in Java&quot; for cross-platform distribution.</font>
<font color="#009900">/* Commented so CodePackager sees it and starts
   a new chapter directory, but so you don't 
   have to worry about the directory where this
   program lives:
package c17;
*/</font>
<font color="#0000ff">import</font> java.util.*;
<font color="#0000ff">import</font> java.io.*;

<font color="#0000ff">class</font> Pr {
  <font color="#0000ff">static</font> <font color="#0000ff">void</font> error(String e) {
    System.err.println(<font color="#004488">&quot;ERROR: &quot;</font> + e);
    System.exit(1);
  }
}

<font color="#0000ff">class</font> IO {
  <font color="#0000ff">static</font> BufferedReader disOpen(File f) {
    BufferedReader in = <font color="#0000ff">null</font>;
    <font color="#0000ff">try</font> {
      in = <font color="#0000ff">new</font> BufferedReader(
        <font color="#0000ff">new</font> FileReader(f));
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;could not open &quot;</font> + f);
    }
    <font color="#0000ff">return</font> in;
  }
  <font color="#0000ff">static</font> BufferedReader disOpen(String fname) {
    <font color="#0000ff">return</font> disOpen(<font color="#0000ff">new</font> File(fname));
  }
  <font color="#0000ff">static</font> DataOutputStream dosOpen(File f) {
    DataOutputStream in = <font color="#0000ff">null</font>;
    <font color="#0000ff">try</font> {
      in = <font color="#0000ff">new</font> DataOutputStream(
        <font color="#0000ff">new</font> BufferedOutputStream(
          <font color="#0000ff">new</font> FileOutputStream(f)));
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;could not open &quot;</font> + f);
    }
    <font color="#0000ff">return</font> in;
  }
  <font color="#0000ff">static</font> DataOutputStream dosOpen(String fname) {
    <font color="#0000ff">return</font> dosOpen(<font color="#0000ff">new</font> File(fname));
  }
  <font color="#0000ff">static</font> PrintWriter psOpen(File f) {
    PrintWriter in = <font color="#0000ff">null</font>;
    <font color="#0000ff">try</font> {
      in = <font color="#0000ff">new</font> PrintWriter(
        <font color="#0000ff">new</font> BufferedWriter(
          <font color="#0000ff">new</font> FileWriter(f)));
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;could not open &quot;</font> + f);
    }
    <font color="#0000ff">return</font> in;
  }
  <font color="#0000ff">static</font> PrintWriter psOpen(String fname) {
    <font color="#0000ff">return</font> psOpen(<font color="#0000ff">new</font> File(fname));
  }
  <font color="#0000ff">static</font> <font color="#0000ff">void</font> close(Writer os) {
    <font color="#0000ff">try</font> {
      os.close();
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;closing &quot;</font> + os);
    }
  }
  <font color="#0000ff">static</font> <font color="#0000ff">void</font> close(DataOutputStream os) {
    <font color="#0000ff">try</font> {
      os.close();
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;closing &quot;</font> + os);
    }
  }
  <font color="#0000ff">static</font> <font color="#0000ff">void</font> close(Reader os) {
    <font color="#0000ff">try</font> {
      os.close();
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;closing &quot;</font> + os);
    }
  }
}

<font color="#0000ff">class</font> SourceCodeFile {
  <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">final</font> String 
    startMarker = <font color="#004488">&quot;</font><font color="#004488">/</font><font color="#004488">/:&quot;</font>, <font color="#009900">// Start of source file</font>
    endMarker = <font color="#004488">&quot;} </font><font color="#004488">/</font><font color="#004488">/</font><font color="#004488">/:~&quot;</font>, <font color="#009900">// End of source</font>
    endMarker2 = <font color="#004488">&quot;}; </font><font color="#004488">/</font><font color="#004488">/</font><font color="#004488">/:~&quot;</font>, <font color="#009900">// C++ file end</font>
    beginContinue = <font color="#004488">&quot;} </font><font color="#004488">/</font><font color="#004488">/</font><font color="#004488">/:Continued&quot;</font>,
    endContinue = <font color="#004488">&quot;</font><font color="#004488">/</font><font color="#004488">/</font><font color="#004488">/:Continuing&quot;</font>,
    packMarker = <font color="#004488">&quot;###&quot;</font>, <font color="#009900">// Packed file header tag</font>
    eol = <font color="#009900">// Line separator on current system</font>
      System.getProperty(<font color="#004488">&quot;line.separator&quot;</font>),
    filesep = <font color="#009900">// System's file path separator</font>
      System.getProperty(<font color="#004488">&quot;file.separator&quot;</font>);
  <font color="#0000ff">public</font> <font color="#0000ff">static</font> String copyright = <font color="#004488">&quot;&quot;</font>;
  <font color="#0000ff">static</font> {
    <font color="#0000ff">try</font> {
      BufferedReader cr =
        <font color="#0000ff">new</font> BufferedReader(
          <font color="#0000ff">new</font> FileReader(<font color="#004488">&quot;Copyright.txt&quot;</font>));
      String crin;
      <font color="#0000ff">while</font>((crin = cr.readLine()) != <font color="#0000ff">null</font>)
        copyright += crin + <font color="#004488">&quot;\n&quot;</font>;
      cr.close();
    } <font color="#0000ff">catch</font>(Exception e) {
      copyright = <font color="#004488">&quot;&quot;</font>;
    }
  }
  <font color="#0000ff">private</font> String filename, dirname,
    contents = <font color="#0000ff">new</font> String();
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> String chapter = <font color="#004488">&quot;c02&quot;</font>;
  <font color="#009900">// The file name separator from the old system:</font>
  <font color="#0000ff">public</font> <font color="#0000ff">static</font> String oldsep;
  <font color="#0000ff">public</font> String toString() {
    <font color="#0000ff">return</font> dirname + filesep + filename;
  }
  <font color="#009900">// Constructor for parsing from document file:</font>
  <font color="#0000ff">public</font> SourceCodeFile(String firstLine, 
      BufferedReader in) {
    dirname = chapter;
    <font color="#009900">// Skip past marker:</font>
    filename = firstLine.substring(
        startMarker.length()).trim();
    <font color="#009900">// Find space that terminates file name:</font>
    <font color="#0000ff">if</font>(filename.indexOf(' ') != -1)
      filename = filename.substring(
          0, filename.indexOf(' '));
    System.out.println(<font color="#004488">&quot;found: &quot;</font> + filename);
    contents = firstLine + eol;
    <font color="#0000ff">if</font>(copyright.length() != 0)
      contents += copyright + eol;
    String s;
    <font color="#0000ff">boolean</font> foundEndMarker = <font color="#0000ff">false</font>;
    <font color="#0000ff">try</font> {
      <font color="#0000ff">while</font>((s = in.readLine()) != <font color="#0000ff">null</font>) {
        <font color="#0000ff">if</font>(s.startsWith(startMarker))
          Pr.error(<font color="#004488">&quot;No end of file marker for &quot;</font> +
            filename);
        <font color="#009900">// For this program, no spaces before </font>
        <font color="#009900">// the &quot;package&quot; keyword are allowed</font>
        <font color="#009900">// in the input source code:</font>
        <font color="#0000ff">else</font> <font color="#0000ff">if</font>(s.startsWith(<font color="#004488">&quot;package&quot;</font>)) {
          <font color="#009900">// Extract package name:</font>
          String pdir = s.substring(
            s.indexOf(' ')).trim();
          pdir = pdir.substring(
            0, pdir.indexOf(';')).trim();
          <font color="#009900">// Capture the chapter from the package</font>
          <font color="#009900">// ignoring the 'com' subdirectories:</font>
          <font color="#0000ff">if</font>(!pdir.startsWith(<font color="#004488">&quot;com&quot;</font>)) {
            <font color="#0000ff">int</font> firstDot = pdir.indexOf('.');
            <font color="#0000ff">if</font>(firstDot != -1)
              chapter = 
                pdir.substring(0,firstDot);
            <font color="#0000ff">else</font>
              chapter = pdir;
          }
          <font color="#009900">// Convert package name to path name:</font>
          pdir = pdir.replace(
            '.', filesep.charAt(0));
          System.out.println(<font color="#004488">&quot;package &quot;</font> + pdir);
          dirname = pdir;
        }
        contents += s + eol;
        <font color="#009900">// Move past continuations:</font>
        <font color="#0000ff">if</font>(s.startsWith(beginContinue))
          <font color="#0000ff">while</font>((s = in.readLine()) != <font color="#0000ff">null</font>)
            <font color="#0000ff">if</font>(s.startsWith(endContinue)) {
              contents += s + eol;
              <font color="#0000ff">break</font>;
            }
        <font color="#009900">// Watch for end of code listing:</font>
        <font color="#0000ff">if</font>(s.startsWith(endMarker) ||
           s.startsWith(endMarker2)) {
          foundEndMarker = <font color="#0000ff">true</font>;
          <font color="#0000ff">break</font>;
        }
      }
      <font color="#0000ff">if</font>(!foundEndMarker)
        Pr.error(
          <font color="#004488">&quot;End marker not found before EOF&quot;</font>);
      System.out.println(<font color="#004488">&quot;Chapter: &quot;</font> + chapter);
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;Error reading line&quot;</font>);
    }
  }
  <font color="#009900">// For recovering from a packed file:</font>
  <font color="#0000ff">public</font> SourceCodeFile(BufferedReader pFile) {
    <font color="#0000ff">try</font> {
      String s = pFile.readLine();
      <font color="#0000ff">if</font>(s == <font color="#0000ff">null</font>) <font color="#0000ff">return</font>;
      <font color="#0000ff">if</font>(!s.startsWith(packMarker))
        Pr.error(<font color="#004488">&quot;Can't find &quot;</font> + packMarker
          + <font color="#004488">&quot; in &quot;</font> + s);
      s = s.substring(
        packMarker.length()).trim();
      dirname = s.substring(0, s.indexOf('#'));
      filename = s.substring(s.indexOf('#') + 1);
      dirname = dirname.replace(
        oldsep.charAt(0), filesep.charAt(0));
      filename = filename.replace(
        oldsep.charAt(0), filesep.charAt(0));
      System.out.println(<font color="#004488">&quot;listing: &quot;</font> + dirname 
        + filesep + filename);
      <font color="#0000ff">while</font>((s = pFile.readLine()) != <font color="#0000ff">null</font>) {
        <font color="#009900">// Watch for end of code listing:</font>
        <font color="#0000ff">if</font>(s.startsWith(endMarker) ||
           s.startsWith(endMarker2)) {
          contents += s;
          <font color="#0000ff">break</font>;
        }
        contents += s + eol;
      }
    } <font color="#0000ff">catch</font>(IOException e) {
      System.err.println(<font color="#004488">&quot;Error reading line&quot;</font>);
    }
  }
  <font color="#0000ff">public</font> <font color="#0000ff">boolean</font> hasFile() { 
    <font color="#0000ff">return</font> filename != <font color="#0000ff">null</font>; 
  }
  <font color="#0000ff">public</font> String directory() { <font color="#0000ff">return</font> dirname; }
  <font color="#0000ff">public</font> String filename() { <font color="#0000ff">return</font> filename; }
  <font color="#0000ff">public</font> String contents() { <font color="#0000ff">return</font> contents; }
  <font color="#009900">// To write to a packed file:</font>
  <font color="#0000ff">public</font> <font color="#0000ff">void</font> writePacked(DataOutputStream out) {
    <font color="#0000ff">try</font> {
      out.writeBytes(
        packMarker + dirname + <font color="#004488">&quot;#&quot;</font> 
        + filename + eol);
      out.writeBytes(contents);
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;writing &quot;</font> + dirname + 
        filesep + filename);
    }
  }
  <font color="#009900">// To generate the actual file:</font>
  <font color="#0000ff">public</font> <font color="#0000ff">void</font> writeFile(String rootpath) {
    File path = <font color="#0000ff">new</font> File(rootpath, dirname);
    path.mkdirs();
    PrintWriter p =
      IO.psOpen(<font color="#0000ff">new</font> File(path, filename));
    p.print(contents);
    IO.close(p);
  }
}

<font color="#0000ff">class</font> DirMap {
  <font color="#0000ff">private</font> Hashtable t = <font color="#0000ff">new</font> Hashtable();
  <font color="#0000ff">private</font> String rootpath;
  DirMap() {
    rootpath = System.getProperty(<font color="#004488">&quot;user.dir&quot;</font>);
  }
  DirMap(String alternateDir) {
    rootpath = alternateDir;
  }
  <font color="#0000ff">public</font> <font color="#0000ff">void</font> add(SourceCodeFile f){
    String path = f.directory();
    <font color="#0000ff">if</font>(!t.containsKey(path))
      t.put(path, <font color="#0000ff">new</font> Vector());
    ((Vector)t.get(path)).addElement(f);
  }
  <font color="#0000ff">public</font> <font color="#0000ff">void</font> writePackedFile(String fname) {
    DataOutputStream packed = IO.dosOpen(fname);
    <font color="#0000ff">try</font> {
      packed.writeBytes(<font color="#004488">&quot;###Old Separator:&quot;</font> +
        SourceCodeFile.filesep + <font color="#004488">&quot;###\n&quot;</font>);
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;Writing separator to &quot;</font> + fname);
    }
    Enumeration e = t.keys();
    <font color="#0000ff">while</font>(e.hasMoreElements()) {
      String dir = (String)e.nextElement();
      System.out.println(
        <font color="#004488">&quot;Writing directory &quot;</font> + dir);
      Vector v = (Vector)t.get(dir);
      <font color="#0000ff">for</font>(<font color="#0000ff">int</font> i = 0; i &lt; v.size(); i++) {
        SourceCodeFile f = 
          (SourceCodeFile)v.elementAt(i);
        f.writePacked(packed);
      }
    }
    IO.close(packed);
  }
  <font color="#009900">// Write all the files in their directories:</font>
  <font color="#0000ff">public</font> <font color="#0000ff">void</font> write() {
    Enumeration e = t.keys();
    <font color="#0000ff">while</font>(e.hasMoreElements()) {
      String dir = (String)e.nextElement();
      Vector v = (Vector)t.get(dir);
      <font color="#0000ff">for</font>(<font color="#0000ff">int</font> i = 0; i &lt; v.size(); i++) {
        SourceCodeFile f = 
          (SourceCodeFile)v.elementAt(i);
        f.writeFile(rootpath);
      }
      <font color="#009900">// Add file indicating file quantity</font>
      <font color="#009900">// written to this directory as a check:</font>
      IO.close(IO.dosOpen(
        <font color="#0000ff">new</font> File(<font color="#0000ff">new</font> File(rootpath, dir),
          Integer.toString(v.size())+<font color="#004488">&quot;.files&quot;</font>)));
    }
  }
}

<font color="#0000ff">public</font> <font color="#0000ff">class</font> CodePackager {
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">final</font> String usageString =
  <font color="#004488">&quot;usage: java CodePackager packedFileName&quot;</font> +
  <font color="#004488">&quot;\nExtracts source code files from packed \n&quot;</font> +
  <font color="#004488">&quot;version of Tjava.doc sources into &quot;</font> +
  <font color="#004488">&quot;directories off current directory\n&quot;</font> +
  <font color="#004488">&quot;java CodePackager packedFileName newDir\n&quot;</font> +
  <font color="#004488">&quot;Extracts into directories off newDir\n&quot;</font> +
  <font color="#004488">&quot;java CodePackager -p source.txt packedFile&quot;</font> +
  <font color="#004488">&quot;\nCreates packed version of source files&quot;</font> +
  <font color="#004488">&quot;\nfrom text version of Tjava.doc&quot;</font>;
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> usage() {
    System.err.println(usageString);
    System.exit(1);
  }
  <font color="#0000ff">public</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> main(String[] args) {
    <font color="#0000ff">if</font>(args.length == 0) usage();
    <font color="#0000ff">if</font>(args[0].equals(<font color="#004488">&quot;-p&quot;</font>)) {
      <font color="#0000ff">if</font>(args.length != 3)
        usage();
      createPackedFile(args);
    }
    <font color="#0000ff">else</font> {
      <font color="#0000ff">if</font>(args.length &gt; 2)
        usage();
      extractPackedFile(args);
    }
  }
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> String currentLine; 
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> BufferedReader in;
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> DirMap dm;
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> 
  createPackedFile(String[] args) {
    dm = <font color="#0000ff">new</font> DirMap();
    in = IO.disOpen(args[1]);
    <font color="#0000ff">try</font> {
      <font color="#0000ff">while</font>((currentLine = in.readLine()) 
          != <font color="#0000ff">null</font>) {
        <font color="#0000ff">if</font>(currentLine.startsWith(
            SourceCodeFile.startMarker)) {
          dm.add(<font color="#0000ff">new</font> SourceCodeFile(
                   currentLine, in));
        }
        <font color="#0000ff">else</font> <font color="#0000ff">if</font>(currentLine.startsWith(
            SourceCodeFile.endMarker))
          Pr.error(<font color="#004488">&quot;file has no start marker&quot;</font>);
        <font color="#009900">// Else ignore the input line</font>
      }
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;Error reading &quot;</font> + args[1]);
    }
    IO.close(in);
    dm.writePackedFile(args[2]);
  }
  <font color="#0000ff">private</font> <font color="#0000ff">static</font> <font color="#0000ff">void</font> 
  extractPackedFile(String[] args) {
    <font color="#0000ff">if</font>(args.length == 2) <font color="#009900">// Alternate directory</font>
      dm = <font color="#0000ff">new</font> DirMap(args[1]);
    <font color="#0000ff">else</font> <font color="#009900">// Current directory</font>
      dm = <font color="#0000ff">new</font> DirMap();
    in = IO.disOpen(args[0]);
    String s = <font color="#0000ff">null</font>;
    <font color="#0000ff">try</font> {
       s = in.readLine();
    } <font color="#0000ff">catch</font>(IOException e) {
      Pr.error(<font color="#004488">&quot;Cannot read from &quot;</font> + in);
    }
    <font color="#009900">// Capture the separator used in the system</font>
    <font color="#009900">// that packed the file:</font>
    <font color="#0000ff">if</font>(s.indexOf(<font color="#004488">&quot;###Old Separator:&quot;</font>) != -1 ) {
      String oldsep = s.substring(
        <font color="#004488">&quot;###Old Separator:&quot;</font>.length());
      oldsep = oldsep.substring(
        0, oldsep. indexOf('#'));
      SourceCodeFile.oldsep = oldsep;
    }
    SourceCodeFile sf = <font color="#0000ff">new</font> SourceCodeFile(in);
    <font color="#0000ff">while</font>(sf.hasFile()) {
      dm.add(sf);
      sf = <font color="#0000ff">new</font> SourceCodeFile(in);
    }
    dm.write();
  }
} <font color="#009900">///:~</font></pre>
</font></blockquote><br />
我们注意到package语句已经作为注释标志出来了。由于这是本章的第一个程序，所以package语句是必需的，用它告诉CodePackager已改换到另一章。但是把它放入包里却会成为一个问题。当我们创建一个包的时候，需要将结果程序同一个特定的目录结构联系在一起，这一做法对本书的大多数例子都是适用的。但在这里，CodePackager程序必须在一个专用的目录里编译和运行，所以package语句作为注释标记出去。但对CodePackager来说，它&ldquo;看起来&rdquo;依然象一个普通的package语句，因为程序还不是特别复杂，不能侦查到多行注释（没有必要做得这么复杂，这里只要求方便就行）。<br />
头两个类是&ldquo;支持／工具&rdquo;类，作用是使程序剩余的部分在编写时更加连贯，也更便于阅读。第一个是Pr，它类似ANSI C的perror库，两者都能打印出一条错误提示消息（但同时也会退出程序）。第二个类将文件的创建过程封装在内，这个过程已在第10章介绍过了；大家已经知道，这样做很快就会变得非常累赘和麻烦。为解决这个问题，第10章提供的方案致力于新类的创建，但这儿的&ldquo;静态&rdquo;方法已经使用过了。在那些方法中，正常的违例会被捕获，并相应地进行处理。这些方法使剩余的代码显得更加清爽，更易阅读。<br />
帮助解决问题的第一个类是SourceCodeFile（源码文件），它代表本书一个源码文件包含的所有信息（内容、文件名以及目录）。它同时还包含了一系列String常数，分别代表一个文件的开始与结束；在打包文件内使用的一个标记；当前系统的换行符；文件路径分隔符（注意要用System.getProperty()侦查本地版本是什么）；以及一大段版权声明，它是从下面这个Copyright.txt文件里提取出来的：<br />
<br />
<blockquote><font size="+1">
<pre><font color="#009900">//////////////////////////////////////////////////</font>
<font color="#009900">// Copyright (c) Bruce Eckel, 1998</font>
<font color="#009900">// Source code file from the book &quot;Thinking in Java&quot;</font>
<font color="#009900">// All rights reserved EXCEPT as allowed by the</font>
<font color="#009900">// following statements: You may freely use this file</font>
<font color="#009900">// for your own work (personal or commercial),</font>
<font color="#009900">// including modifications and distribution in</font>
<font color="#009900">// executable form only. Permission is granted to use</font>
<font color="#009900">// this file in classroom situations, including its</font>
<font color="#009900">// use in presentation materials, as long as the book</font>
<font color="#009900">// &quot;Thinking in Java&quot; is cited as the source. </font>
<font color="#009900">// Except in classroom situations, you may not copy</font>
<font color="#009900">// and distribute this code; instead, the sole</font>
<font color="#009900">// distribution point is http://www.BruceEckel.com </font>
<font color="#009900">// (and official mirror sites) where it is</font>
<font color="#009900">// freely available. You may not remove this</font>
<font color="#009900">// copyright and notice. You may not distribute</font>
<font color="#009900">// modified versions of the source code in this</font>
<font color="#009900">// package. You may not use this file in printed</font>
<font color="#009900">// media without the express permission of the</font>
<font color="#009900">// author. Bruce Eckel makes no representation about</font>
<font color="#009900">// the suitability of this software for any purpose.</font>
<font color="#009900">// It is provided &quot;as is&quot; without express or implied</font>
<font color="#009900">// warranty of any kind, including any implied</font>
<font color="#009900">// warranty of merchantability, fitness for a</font>
<font color="#009900">// particular purpose or non-infringement. The entire</font>
<font color="#009900">// risk as to the quality and performance of the</font>
<font color="#009900">// software is with you. Bruce Eckel and the</font>
<font color="#009900">// publisher shall not be liable for any damages</font>
<font color="#009900">// suffered by you or any third party as a result of</font>
<font color="#009900">// using or distributing software. In no event will</font>
<font color="#009900">// Bruce Eckel or the publisher be liable for any</font>
<font color="#009900">// lost revenue, profit, or data, or for direct,</font>
<font color="#009900">// indirect, special, consequential, incidental, or</font>
<font color="#009900">// punitive damages, however caused and regardless of</font>
<font color="#009900">// the theory of liability, arising out of the use of</font>
<font color="#009900">// or inability to use software, even if Bruce Eckel</font>
<font color="#009900">// and the publisher have been advised of the</font>
<font color="#009900">// possibility of such damages. Should the software</font>
<font color="#009900">// prove defective, you assume the cost of all</font>
<font color="#009900">// necessary servicing, repair, or correction. If you</font>
<font color="#009900">// think you've found an error, please email all</font>
<font color="#009900">// modified files with clearly commented changes to:</font>
<font color="#009900">// Bruce@EckelObjects.com. (please use the same</font>
<font color="#009900">// address for non-code errors found in the book).</font>
<font color="#009900">//////////////////////////////////////////////////</font></pre>
</font></blockquote><br />
从一个打包文件中提取文件时，当初所用系统的文件分隔符也会标注出来，以便用本地系统适用的符号替换它。<br />
当前章的子目录保存在chapter字段中，它初始化成c02（大家可注意一下第2章的列表正好没有包含一个打包语句）。只有在当前文件里发现一个package（打包）语句时，chapter字段才会发生改变。<br />
<br />
1. 构建一个打包文件<br />
第一个构建器用于从本书的ASCII文本版里提取出一个文件。发出调用的代码（在列表里较深的地方）会读入并检查每一行，直到找到与一个列表的开头相符的为止。在这个时候，它就会新建一个SourceCodeFile对象，将第一行的内容（已经由调用代码读入了）传递给它，同时还要传递BufferedReader对象，以便在这个缓冲区中提取源码列表剩余的内容。<br />
从这时起，大家会发现String方法被频繁运用。为提取出文件名，需调用substring()的过载版本，令其从一个起始偏移开始，一直读到字串的末尾，从而形成一个&ldquo;子串&rdquo;。为算出这个起始索引，先要用length()得出startMarker的总长，再用trim()删除字串头尾多余的空格。第一行在文件名后也可能有一些字符；它们是用indexOf()侦测出来的。若没有发现找到我们想寻找的字符，就返回-1；若找到那些字符，就返回它们第一次出现的位置。注意这也是indexOf()的一个过载版本，采用一个字串作为参数，而非一个字符。<br />
解析出并保存好文件名后，第一行会被置入字串contents中（该字串用于保存源码清单的完整正文）。随后，将剩余的代码行读入，并合并进入contents字串。当然事情并没有想象的那么简单，因为特定的情况需加以特别的控制。一种情况是错误检查：若直接遇到一个startMarker（起始标记），表明当前操作的这个代码列表没有设置一个结束标记。这属于一个出错条件，需要退出程序。<br />
另一种特殊情况与package关键字有关。尽管Java是一种自由形式的语言，但这个程序要求package关键字必须位于行首。若发现package关键字，就通过检查位于开头的空格以及位于末尾的分号，从而提取出包名（注意亦可一次单独的操作实现，方法是使用过载的substring()，令其同时检查起始和结束索引位置）。随后，将包名中的点号替换成特定的文件分隔符&mdash;&mdash;当然，这里要假设文件分隔符仅有一个字符的长度。尽管这个假设可能对目前的所有系统都是适用的，但一旦遇到问题，一定不要忘了检查一下这里。<br />
默认操作是将每一行都连接到contents里，同时还有换行字符，直到遇到一个endMarker（结束标记）为止。该标记指出构建器应当停止了。若在endMarker之前遇到了文件结尾，就认为存在一个错误。<br />
<br />
2. 从打包文件中提取<br />
第二个构建器用于将源码文件从打包文件中恢复（提取）出来。在这儿，作为调用者的方法不必担心会跳过一些中间文本。打包文件包含了所有源码文件，它们相互间紧密地靠在一起。需要传