[code=java]import java.io.*;
class pipestreamtest
{
public static void main(String [] args)
{
try
{
Thread t1=new Sender();
Thread t2=new Receiver();
PipedOutputStream out=t1.getOutputStream();
PipedInputStream in=t2.getInputStream();
out.connect(in);
t1.start();
t2.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class Sender extends Thread
{
private PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getOutputStream()
{
return out;
}
public void run()
{
String s= new String("hello,I'm sender!");
try
{
out.write(s.getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
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("from sender:"+s);
in.close();
}
catch(Exception e)
{e.printStackTrace();}
}
}[/code]每次编译都说第10行和第11行的符号找不到,就只在点那个地方。。。我很无语,我都直接把方法名贴过去了,都不行。。。 |
|