<%!
int num = 0;
File file = new File("count.txt");
synchronized void Count()
{//计算访问次数的同步方法
if(!file.exists())
{
num++;
try
{
file.createNewFile();
FileOutputStream out = new FileOutputStream("count.txt");
DataOutputStream dataOut = new DataOutputStream(out);
dataOut.write(num);
out.close();
dataOut.close();
}
catch(IOException ee)
{
}
}
else
{
try
{
FileInputStream in = new FileInputStream("count.txt");
DataInputStream dataIn = new DataInputStream(in);
num = dataIn.readInt();
num++;
in.close();
dataIn.close();
FileOutputStream out = new FileOutputStream("count.txt");
DataOutputStream dataOut = new DataOutputStream(out);
dataOut.writeInt(num);
out.close();
dataOut.close();
}
catch(IOException ee)
{
}
}
}
%>
<%
Count();
%>
你是第<%= num %>访问的人。。。