这样声明对吗??在线等!

ljliang 2003-04-09 10:29:23
在jsp中这样声明:
<%!
public class OutputPicture{
private InputStream in;
public OutputPicture(){

}
public setMyInputStream(InputStream in){
this.in=in;
}
public void outputPhoto(){
byte[] b = new byte[1024*1024];
int len;
OutputStream out1;
while((len=in.read(b))>0)
out1.write(b,0,len);
out1.flush();
in.close();
}
}
%>
调用: OutputPicture putpicture=new OutputPicture();
putpicture.setMyInputStream(in); <center><imgsrc=putpicture.outputPhoto() width="5" height="6"></center>

总是有错误:invalid method declaration; return type required
public setMyInputStream(InputStream in){

怎么办?请帮忙!

...全文
6 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ljliang 2003-04-09
OutputStream out1=new OutputStream();//// 这行如何改???
回复
ljliang 2003-04-09
大家看我的程序,我用什么来初始化呀?我真是不清楚!<%!
public class OutputPicture{
private InputStream in;
public OutputPicture(){

}
public void setMyInputStream(InputStream in){
this.in=in;
}
public void outputPhoto(){
byte[] b = new byte[1024*1024];
int len;
OutputStream out1=new OutputStream();
try{
while((len=in.read(b))>0)
out1.write(b,0,len);
out1.flush();
in.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
%>
回复
whodsow 2003-04-09
OutputStream outl=new OutputStream(...);
就完成初始化了。
回复
lljjsp 2003-04-09
我也有同样的问题,就是OutputStream out1未初始化,不知如何初始化?我也不知道,谁知道?
回复
gaojunbo 2003-04-09
out1.write(b,0,len);
这一句要放在
try
{}
catch()
{}
回复
ljliang 2003-04-09
up
回复
gaojunbo 2003-04-09
OutputStream out1;
是一个局部变量,在便用前必须先初始张才行.
回复
ljliang 2003-04-09
各位说得很对。但是,现在又有新错误:
45: unreported exception java.io.IOException; must be caught or declared to be thrown

46: variable out1 might not have been initialized

46: unreported exception java.io.IOException; must be caught or declared to be thrown

请各位在看看!谢谢!

回复
moumouren 2003-04-09
/* 除了构造方法,其他的都必须声明返回值 */
public void setMyInputStream(InputStream in){
this.in=in;
}
回复
zez 2003-04-09
楼上说了 :)
回复
gaojunbo 2003-04-09
public setMyInputStream(InputStream in)
{
his.in=in;
}
此方法没有写返回值的类型,如无返回值要写上void,

public void setMyInputStream(InputStream in){
this.in=in;
}
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-09 10:29
社区公告
暂无公告