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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 黔南| 织金县| 白河县| 东城区| 陇川县| 乐平市| 育儿| 冕宁县| 红桥区| 上杭县| 高州市| 新疆| 金湖县| 光泽县| 平舆县| 建瓯市| 邹平县| 垦利县| 扶余县| 临城县| 桃园县| 彭阳县| 繁峙县| 纳雍县| 濉溪县| 澄城县| 汝南县| 西贡区| 象州县| 葫芦岛市| 万全县| 富顺县| 女性| 南汇区| 金堂县| 蒙自县| 内丘县| 霍州市| 闸北区| 新沂市| 长海县|