隨筆-86  評論-767  文章-3  trackbacks-3

          package testcounter;

          /**
           *

          Title:


           *

          Description:


           *

          Copyright: Copyright (c) 2003


           *

          Company: riozn


           * @zhouzm
           * @version 1.0
           */

          import java.io.*;

          public class counter {
            private String currentRecord=null;
            private BufferedReader file=null;
            private String path=null;

            public counter() {

            }

            public String readFile(String fileName){
              path=fileName;
              String returnStr=null;
              try{
                file=new BufferedReader(new FileReader(path));
              }
              catch(FileNotFoundException e1){
                System.out.println("文件沒有找到!");
                return null;
              }
              try{
                currentRecord=file.readLine();
              }
              catch(IOException e){
                System.out.println("讀取數據錯誤.");
                return null;
              }
              if (currentRecord==null)
                returnStr="100000";
              else{
                returnStr=currentRecord;
              }
              return returnStr;
            }

            public void writeFile(String fileName, String counter) throws FileNotFoundException{
              path=fileName;
              int writeStr=Integer.parseInt(counter)+1;
              try{
                PrintWriter pw=new PrintWriter(new FileOutputStream(path));
                pw.println(writeStr);
                pw.close();
              }
              catch(IOException e){
                System.out.println("寫入文件錯誤"+e.getMessage());
              }
            }
          }
          上邊這個是計數器的例子
          計數器的數字就是放在一個文本文件中,跟你要求的ini文件是一樣的
          你稍微修改下上面的程序就可以了:)

          posted on 2005-01-14 15:08 eamoi 閱讀(1283) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 潮安县| 新宾| 静安区| 南投市| 东港市| 肥城市| 石景山区| 饶河县| 涡阳县| 台东县| 曲靖市| 杨浦区| 赤壁市| 麻栗坡县| 富裕县| 望谟县| 武功县| 香河县| 孝昌县| 青川县| 丰都县| 宜兰县| 鹤岗市| 新乐市| 五寨县| 河北省| 大洼县| 隆德县| 大理市| 白银市| 天峨县| 汶上县| 沙湾县| 应城市| 哈巴河县| 曲阜市| 晋城| 广东省| 牟定县| 葵青区| 彰化市|