public class TestPipeStream { public static void main(String[] args) {
try
{
Thread t1=new Sender();
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream()
{
return out;
}t1不能调用getPipedOutputStream()方法,纳闷ing!,谁能告诉我为什么呀,该怎么解决,在线等待
try
{
Thread t1=new Sender();
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream()
{
return out;
}t1不能调用getPipedOutputStream()方法,纳闷ing!,谁能告诉我为什么呀,该怎么解决,在线等待
public class TestPipeStream { public static void main(String[] args) { Thread t1=new Sender();
}
static class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream()
{
return out;
}
}
}或者public class TestPipeStream { public static void main(String[] args) {
TestPipeStream t = new TestPipeStream();
Thread t1=t.new Sender(); //你调用内部类,没有外部类的引用是不可调用的!
}
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream()
{
return out;
}
}
}
public class TestPipeStream { public static void main(String[] args) {
//Thread t1=new Thread();
//Thread t2=new Thread();
try
{
Thread t1=new Sender();
Thread t2=new Recever();
t1.getPipedOutputStream(); }
catch(IOException e2)
{
e2.printStackTrace();
}
}
}
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream() {
return out;
}
public void run()
{
try
{
out.write("123".getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Recever extends Thread
{
PipedInputStream in=new PipedInputStream();
public PipedInputStream getPipedInputStream()
{
return in;
}
public void run()
{
byte[] b=new byte[1024];
try
{
int len=in.read(b);
System.out.println(new String(b,0,len));
}
catch(IOException e1)
{
e1.printStackTrace();
}
}
}
import java.io.PipedOutputStream;public class TestPipeStream { public static void main(String[] args) {
try {
Sender t1 = new Sender();
t1.getPipedOutputStream();
} catch (Exception e) { }
}
}class Sender extends Thread { PipedOutputStream out = new PipedOutputStream();
public PipedOutputStream getPipedOutputStream() {
return out;
}
}
public class TestPipeStream { public static void main(String[] args) {
//Thread t1=new Thread();
//Thread t2=new Thread();
try
{
Thread t1=new Sender();
Thread t2=new Recever();
t1.getPipedOutputStream();//这边报错
}
catch(IOException e2)
{
e2.printStackTrace();
}
}
}
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream() {
return out;
}
public void run()
{
try
{
out.write("123".getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Recever extends Thread
{
PipedInputStream in=new PipedInputStream();
public PipedInputStream getPipedInputStream()
{
return in;
}
public void run()
{
byte[] b=new byte[1024];
try
{
int len=in.read(b);
System.out.println(new String(b,0,len));
}
catch(IOException e1)
{
e1.printStackTrace();
}
}
}
public class TestPipeStream { public static void main(String[] args) {
//Thread t1=new Thread();
//Thread t2=new Thread();
try
{
Thread t1=new Sender();
Thread t2=new Recever();
t1.getPipedOutputStream();//这边报错
}
catch(IOException e2)
{
e2.printStackTrace();
}
}
}
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream() {
return out;
}
public void run()
{
try
{
out.write("123".getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Recever extends Thread
{
PipedInputStream in=new PipedInputStream();
public PipedInputStream getPipedInputStream()
{
return in;
}
public void run()
{
byte[] b=new byte[1024];
try
{
int len=in.read(b);
System.out.println(new String(b,0,len));
}
catch(IOException e1)
{
e1.printStackTrace();
}
}
}
import java.io.*;
public class TestPipeStream { public static void main(String[] args) {
Sender t1=new Sender(); //这么改,因为Thread 类没有getPipedOutputStream方法,所以抱错,虽然执行的不是Thread 的方法,但是编译期间检查的!
Recever t2=new Recever();
t1.getPipedOutputStream();
}
}
class Sender extends Thread
{
PipedOutputStream out=new PipedOutputStream();
public PipedOutputStream getPipedOutputStream() {
return out;
}
public void run()
{
try
{
out.write("123".getBytes());
out.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Recever extends Thread
{
PipedInputStream in=new PipedInputStream();
public PipedInputStream getPipedInputStream()
{
return in;
}
public void run()
{
byte[] b=new byte[1024];
try
{
int len=in.read(b);
System.out.println(new String(b,0,len));
}
catch(IOException e1)
{
e1.printStackTrace();
}
}
}