Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 安装/配置/编译/环境  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 为什么编译通不过?
Butterfly_125





发贴: 26
积分: 0
于 2005-07-21 02:28 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.io.*;
public class PipeStreamTest
{
  public static void main(String args[])
  {
    try
    {
      Thread e1 = new Sender();
      Thread e2 = new Receiver();
      PipedOutputStream out = e1.getOutputStream();
      PipedInputStream in = e2.getInputStream();
      out.connect(in);
      e1.start();
      e2.start();
    }
    catch(IOException e)
    {
      System.out.println(e.getMessage());
    }
  }
}

class Sender extends Thread
{
  private PipedOutputStream out = new PipedOutputStream();
  public PipedOutputStream getOutputStream()  //PipedOutputStream为返回类型
  {
    return out;
  }
  public void run()
  {
    String s = new String("My name is YuanPing");
    try
    {
      out.write(s.getBytes());
      out.close();
    }
    catch(IOException e)
    {
      System.out.println(e.getMessage());
    }
  }
}

class Receiver extends Thread
{
  private PipedInputStream in = new PipedInputStream();
  public PipedInputStream getInputStream()
  {
    return in;
  }
  public void run()
  {
    String s = null;
    byte bt[] = new byte[1024];
    int len;
    try
    {
      len = in.read(bt);
      s = new String(bt,0,len);
      System.out.println("The following message comes from Sender:\n" + s);
      in.close();
    }
    catch(IOException e)
    {
      System.out.println(e.getMessage());
    }
  }
}

编译报的错:
D:\PipeStreamTest.java:10: 找不到符号
符号: 方法 getOutputStream()
位置: 类 java.lang.Thread
PipedOutputStream out = e1.getOutputStream();
^
D:\PipeStreamTest.java:11: 找不到符号
符号: 方法 getInputStream()
位置: 类 java.lang.Thread
PipedInputStream in = e2.getInputStream();
^
2 错误

getOutputStream()getInputStream()明明在Sender和Receiver中自己定义了啊!
为什么还这报错?高手们,帮帮忙吧!Sad




话题树型展开
人气 标题 作者 字数 发贴时间
6673 为什么编译通不过? Butterfly_125 1883 2005-07-21 02:28
5435 Re:为什么编译通不过? ranchgirl 2590 2005-07-21 06:01
5647 Re:为什么编译通不过? Butterfly_125 244 2005-07-21 14:21

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923