日期:2014-05-17  浏览次数:20991 次

java提示找不到符号
import java.io.*;


public class TestPipeIoStream
{
public static void main( String[] args ) throws Exception
{
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
new ThreadSend(pos).run();
new ThreadRecv(pis).run();
}
}

class ThreadSend extends  Thread
{
PipedOutputStream pos;

ThreadSend( PipedOutputStream p )
{
pos = p;
}
public void run()
{
try
{
pos.write("every one is ".getBytes());
pos.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}

class ThreadRecv extends  Thread
{
PipedInputStream pis;

ThreadRecv( PipedInputStream p )
{
pis = p;
}
public void run()
{
try
{
Byte[] buf = new Byte[100];
int len = pis.read(buf);
System.out.println(new String(buf,0,len));
}catch(Exception e)
{
e.printStackTrace();
}
}
}
编译错误:
TestPipeIoStream.java:50: 找不到符号
符号: 方法 read(java.lang.Byte[])
位置: 类 java.io.PipedInputStream
                        int len = pis.read(buf);
                                     ^
TestPipeIoStream.java:51: 找不到符号
符号: 构造函数 String(java.lang.Byte[],int,int)
位置: 类 java.lang.String
                        System.out.println(new String(buf,0,len));
                                           ^
2 错误

------解决方案--------------------
找不到符号好像是没有引入类还是定义类什么的
------解决方案--------------------
Byte[] buf = new Byte[100];
改成
byte[] buf = new byte[100];
------解决方案--------------------
没有缩进的代码真心难看。

你run方法里的
pis变量没有申明。

另:你知道什么是变量的作用域吗?
------解决方案--------------------
2楼正解

Byte[] buf = new Byte[100];
改成
byte[] buf = new byte[100];