JSP写的访问人数出错的问题 高手进
<%@page import= "java.io.* "%>
<%
BufferedReader file;
String countFile = request.getRealPath( "count.txt ");
file = new BufferedReader(new FileReader(countFile));
String readStr = null;
int writeStr = 0;
try
{
readStr = file.readLine();
}
catch(
IOException e)
{
System.out.println( "读取数据错误 ");
}
if(readStr==null){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( "读取数据错误 ");}
%>
高手帮小弟看看代码有错吗,为什么我服务器重起以后,有时候count.txt值会被清空,
解决了马上给分
------解决方案--------------------顶
------解决方案--------------------初始文件里的第一行数据是整型么?
如果没有数据,应该是出异常了