|
Java学习者论壇
程序中判斷了count.txt的文件是否存在,我把访问量打算记錄在count.txt,如果存在就累加,如果不存在文件就建立. 可是为什么每次都显示0访客呢.
count.txt也不自动建立,希望各位高手帮忙看看,我用myclipse编写的,沒有提示字母的拼写錯误
<%@ page contentType="text/HTML;charset=GB2312" %>
<%@ page import="java.io.*" %>
<HTML>
<BODY BGCOLOR=cyan>
<%!
int number=0;
File file=new File("count.txt");
synchronized void countPeople()
{
if(!file.exists())
{
number++;
try {
file.createNewFile();
FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();
dataOut.close();
}
catch(IOException ee){}
}
else
{
try{
FileInputStream in=new FileInputStream("count.txt");
DataInputStream dataIn=new DataInputStream(in);
number=dataIn.readInt();
number++;
in.close();
dataIn.close();
FileOutputStream out=new FileOutputStream("count.txt");
DataOutputStream dataOut=new DataOutputStream(out);
dataOut.writeInt(number);
out.close();
dataOut.close();
}
catch(IOException ee){}
}
}
%>
<% countPeople(); %>
<font size=4>您是第<%=number %>个访问本站的客户</font>
</body>
</html>
欢迎來到Java學习者论坛,转载请注明地址:http://www.javaxxz.com. |
|