黑马程序员技术交流社区

标题: 线程加入管道流 [打印本页]

作者: 李娟    时间: 2011-12-23 15:45
标题: 线程加入管道流
本帖最后由 李娟 于 2011-12-23 23:08 编辑

class Write implements Runnable
{       
        private PipedOutputStream out;
        Write(PipedOutputStream out)
        {
                this.out = out;
        }
        public void run()
        {
                try
                {
                        System.out.println("开始写入数据,等待6秒后。");
                        Thread.sleep(6000);                       //此行报错,可是视频上能运行出来
                        out.write("piped lai la".getBytes());
                        out.close();
                }
                catch (IOException e)
                {
                        throw new RuntimeException("管道输出流失败");
                }
        }
}
作者: 刘基军    时间: 2011-12-23 15:51
1.public static void sleep(long millis)
                  throws InterruptedException
2.
java.lang.Object
  java.lang.Throwable
      java.lang.Exception
          java.lang.InterruptedException
你需要对调用sleep()可能发生的InterruptedException异常进行捕获或抛出处理
作者: 马德强    时间: 2011-12-23 15:52
Thread.sleep(6000);     会抛出  InterruptedException异常,你没处理该异常,当然报错了。
要学会看错误信息




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2