您的位置:程序门 -> java -> j2se / 基础类



刚开始学编程,请问这段代码哪里错了?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


刚开始学编程,请问这段代码哪里错了?[已结贴,结贴人:jiangjinsong]
发表于:2007-01-31 15:49:44 楼主
import   java.io.*;
public   class   pipestreamtest
{
public   static   void   main(string   []   args)
{
try{
thread   t1=new   sender();
thread   t2=new   receiver();
pipedoutputstream   out=t1.getoutputstream();
pinedinputstream   in=t2.getinputstream();
out.connect(in);
t1.start();
t2.start();
}

catch(exception   e)
{
system.out.println(e.getmessage());
}
}
}

class   sender   extends   thread
{

private   pipedoutputstream   out=new   pipedoutputstream();
public   pipedoutputstream   getoutputstream()
{
return   out;
}
public   void   run()
{
string   s=new   string( "hello,receiver,how   are   you ");
try
{
out.write(s.getbytes());
out.close();
}
catch(exception   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[]   buf   =new   byte[1024];
try
{
int   len=in.read(buf);
s=new   string   (buf,0,len);
system.out.println( "the   follow   message   comes   from   sed=nder:\n "+s);
in.close();
}
catch(ioexception   e)
{
system.out.println(e.getmessage());
}

}
}
发表于:2007-01-31 15:53:361楼 得分:0
pipedoutputstream   和pipedinputstream   要import   进来
发表于:2007-01-31 15:54:232楼 得分:20
thread   t1=new   sender();
thread   t2=new   receiver();
改为:
sender   t1=new   sender();
receiver   t2=new   receiver();
pinedinputstream改为:pipedinputstream
张孝祥java   就业培训教程   上代码有的有错误,最好看视频!
发表于:2007-01-31 16:58:023楼 得分:0
谢谢!


快速检索

最新资讯
热门点击