问题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()不能识别
为什么啊?
解决方案 »
- HttpURLConnection 得不到cookie里的sessionID?
- 请教Quartz的未触发指令的几个调度策略的具体意思是什么?帮忙解释一下,谢谢!
- 对于java.sql.clob的一点疑问!
- 真郁闷这么简单的题都不会,求助!!
- 求一分割字符串的正则表达式
- 如何在textarea中保存格式??????
- ResultSet.getString()无法读取值为0000-00-00 00:00:00的Mysql datetime型数据
- JAVA应用程序开发的困惑
- 有关swing中Table的问题?(求助)
- 急急急!!!上海地区有没有12月份的java培训???
- 如何来检查输入的文本式合法的日期????????
- 关于视频监控
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时,异常只能"窄化"
都不能抛,只能抓了?