XfoxKing's Blog

          喜愛Java
          隨筆 - 12, 文章 - 0, 評論 - 2, 引用 - 0
          數據加載中……

          JSP中對文件讀寫

          	<%!
          		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 %>訪問的人。。。

          posted on 2009-10-26 07:35 XfoxKing 閱讀(294) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 龙里县| 富裕县| 扎赉特旗| 阜康市| 元阳县| 金阳县| 天台县| 韩城市| 大同县| 沐川县| 青冈县| 迭部县| 定襄县| 普兰县| 太白县| 绵阳市| 嵩明县| 武乡县| 大化| 襄垣县| 泽库县| 东山县| 阿巴嘎旗| 安新县| 佛学| 建瓯市| 景东| 沅江市| 进贤县| 铜川市| 德惠市| 临潭县| 苍山县| 和平区| 华蓥市| 拉萨市| 安新县| 乌兰浩特市| 建宁县| 昌都县| 西畴县|