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

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){

怎么办?请帮忙!

...全文
82 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
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;
}

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧