首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

跪计数器有关问题!

2012-02-06 
跪求一个计数器问题!!!!javabean:packagech10importjava.io.*publicclassFileWRBean{privateStringpath

跪求一个计数器问题!!!!
javabean:
package   ch10;
import   java.io.*;
public   class   FileWRBean
{
private   String   path;
private   String   str_written;
private   String   str_read;
public   FileWRBean()
{
}
public   String   getPath()
{
return   path;
}
public   void   setPath(String   path)
{
this.path=path;
}
public   String   getStr_written()
{
return   str_written;
}
public   void   setStr_written(String   str_written)
{
this.str_written=str_written;
}
public   String   getStr_read()
{
return   str_read;
}
public   void   setStr_read(String   str_read)
{
this.str_read=str_read;
}
public   int   ReadFile()
{
try
{
FileReader   freader=new   FileReader(path);
BufferedReader   bfdreader=new   BufferedReader(freader);
str_read=bfdreader.readLine();
String   str_line=bfdreader.readLine();
while(str_line!=null)
{
str_read=str_read+ " <br> "+str_line;
str_line=bfdreader.readLine();
}
bfdreader.close();
freader.close();
return   0;
}
catch   (IOException   e)
{
System.out.println( "文件读取错误! ");
return   -1;
}
}
public   int   WriterOver()
{
try
{
FileWriter   fwriter=new   FileWriter(path);
BufferedWriter   bfwriter=new   BufferedWriter(fwriter);
bfwriter.write(str_written,0,str_written.length());
bfwriter.flush();
bfwriter.close();
return   0;
}
catch   (IOException   e)
{
System.out.println( "文件写入错误! ");
return   -1;
}
}
public   int   WriteAppend()
{
try
{
FileWriter   fwriter=new   FileWriter(path,true);
BufferedWriter   bfwriter=new   BufferedWriter(fwriter);
bfwriter.newLine();
bfwriter.write(str_written,0,str_written.length());
bfwriter.flush();
bfwriter.close();
        return   0;
}
catch   (IOException   e)
{
System.out.println( "文件写错误! ");
return   -1;
}
}
}
jsp: <%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<jsp:useBean   id= "fwrBean "   class= "ch10.FileWRBean "   scope= "session "/>
<%@   page   import= "java.io.* "%>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 计数器 </title>
</head>

<body>
<center>
<%
      String   path=request.getRealPath( "/ ")+ "ch11 "+ "file3.txt ";
      fwrBean.setPath(path);
      fwrBean.ReadFile();


      int   count=Integer.parseInt(fwrBean.getStr_read())+1;
      String   str_written=String.valueOf(count);
      fwrBean.setStr_written(str_written);
      fwrBean.WriterOver();
%>
总共访问人次为: <%=str_written%>
</center>
</body>
</html>
执行时,出现了NumberFormatException异常
怎么解决阿?
我在执行前已经给file3.txt存入0了

[解决办法]
String path=request.getRealPath( "/ ")+ "ch11 "+ "file3.txt ";
"ch11/ "?
[解决办法]
你建立了file3.txt了吗?
[解决办法]
String path=request.getRealPath( "/ ")+ "ch11 "+ "file3.txt ";

是你的地址错了
改为:String path=request.getRealPath( "/ ")+ "ch11/ "+ "file3.txt ";
就可以了

热点排行