问题1
byte [] buf = new byte[1024];
FileInputStream in = new FileInputStream("1.txt");
int len = in.read(buf);
上面的代码中
len 保存的是读取1.TXT的部分内容吗
还是读到内容的长度啊?问题2
byte [] buf = new byte[1024];
byte 是基本类型的啊 为什么可以用NEW 来创建?
应该 是用Byte啊?问题3
class Pip extends Thread
{
private PipedInputStream in = new PipedInputStream();
public PipedInputStream getInputStream()
{
return in;
}
public void run() throws Exception
{
byte [] buf = new byte[1024];
int len = in.read(buf);// aa处
System.out.println(new String(buf,0,len);
in.close();
}
} 编译说 aa处的in.read()不能识别
为什么啊?
byte [] buf = new byte[1024];
FileInputStream in = new FileInputStream("1.txt");
int len = in.read(buf);
上面的代码中
len 保存的是读取1.TXT的部分内容吗
还是读到内容的长度啊?问题2
byte [] buf = new byte[1024];
byte 是基本类型的啊 为什么可以用NEW 来创建?
应该 是用Byte啊?问题3
class Pip extends Thread
{
private PipedInputStream in = new PipedInputStream();
public PipedInputStream getInputStream()
{
return in;
}
public void run() throws Exception
{
byte [] buf = new byte[1024];
int len = in.read(buf);// aa处
System.out.println(new String(buf,0,len);
in.close();
}
} 编译说 aa处的in.read()不能识别
为什么啊?
import java.io.PipedInputStream;public class Pip extends Thread {
private PipedInputStream in = new PipedInputStream(); public PipedInputStream getInputStream() {
return in;
} public void run() {
byte[] buf = new byte[1024];
int len = 0;
try {
len = in.read(buf);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(new String(buf, 0, len));
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
前两个问题我明白了
但第三个问题
我还是没有弄明白
我的是抛异常
你是CATCH异常
难到是这个原因吗?
由于Thread的run()并没有抛出异常,所以你子类override run()不能增加异常
也就是子类进行override时,异常只能"窄化"
都不能抛,只能抓了?