一个计数器的javabeen!
type Status report
message count.txt (No such file or directory)
description The requested resource (count.txt (No such file or directory)) is not available.
------

回复此文章 |

//counter.java
package counter;
import java.io.*;
public class counter extends Object
{
public String path=
"";
public String doCount() throws FileNotFoundException
{
BufferedReader File;
String countFile =path;
File =new BufferedReader(new FileReader(countFile));
String readStr =
"";
int writeStr =1;
try
{
readStr =File.readLine();
}
catch(IOException e)
{
System.out.println(
"读取数据错误.");
}
if(readStr ==
""){readStr="没有任何记录";}
else
{
writeStr=Integer.parseInt(readStr)+1;
}
try
{
PrintWriter pw = new PrintWriter(new FileOutputStream(countFile));
pw.println(writeStr);
pw.close();
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
return readStr;

}

}

------

回复此文章 |

<jsp:useBean id="counter" scope="request" class="counter.counter"/>
<%@page contentType="text/html;charset=gb2312"%>
<%
counter.path="count.txt";
String count=counter.doCount();
%>
<%=count%>

//////////////////////////////////////////////////////
它的提示说找不到counter.txt文件,不知如何解决!?求助!!
------

回复此文章 |

其实,刚刚有这个可运行的环境,还真不知道如何去学习javaBeen!
请hofman指条明路!
Thank you!
------
回复此文章 |

主要是缺少文件路径,已经替你搞定了。
改正后的文件是beanTest.jsp.
文件的读写应该用绝对路径,例如/home/sunchj/public_html/counter/count.txt,
而不能用相对路径,如count.txt。
------


hofman   2005-11-19 22:13:21 评论:0   阅读:1706   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog