2011年计算机二级JAVA知识点:JavaIO包中的Decorator模式

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论

  *

  */

  public class Test {

  public static void main(String[] args){

  byte[] buffer = new byte[1024];

  /**

  * Create input stream from the standard input.

  */

  InputStream in = new BufferedInputStream(new DataInputStream(System.in));

  /**

  * write to the standard output.

  */

  OutputStream out = new SkipSpaceOutputStream(new DataOutputStream(System.out));

  try {

  System.out.println("Please input your words: ");

  int n = in.read(buffer,0,buffer.length);

  for(int i=0;i〈n;i++){

  out.write(buffer[i]);

  }

  } catch (IOException e) {

  e.printStackTrace();

  }

  }

  }

  执行以上测试程序,将要求用户在console窗口中输入信息,程序将过滤掉信息中的空格,并将最后的结果输出到console窗口。比如:

  以下是引用片段:

  Please input your words:

  a b c d e f

  abcdef

  总 结

  在java.io包中,不仅OutputStream用到了Decorator设计模式,InputStream,Reader,Writer等都用到了此模式。而作为一个灵活的,可扩展的类库,JDK中使用了大量的设计模式,比如在Swing包中的MVC模式,RMI中的Proxy模式等等。对于JDK中模式的研究不仅能加深对于模式的理解,而且还有利于更透彻的了解类库的结。

  点击查看:2011年计算机二级考试JAVA知识点整理汇总

上一页345下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答