隨筆-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
          主站蜘蛛池模板: 大石桥市| 津南区| 乐陵市| 佛冈县| 景德镇市| 历史| 岱山县| 界首市| 龙井市| 琼海市| 贡嘎县| 当雄县| 旅游| 余庆县| 龙川县| 巴中市| 连云港市| 哈巴河县| 米易县| 闸北区| 金川县| 甘肃省| 扎赉特旗| 都江堰市| 石河子市| 双牌县| 西充县| 太湖县| 辽阳县| 宜良县| 平塘县| 高安市| 甘南县| 西乌珠穆沁旗| 康平县| 南岸区| 嘉鱼县| 河津市| 淮阳县| 临澧县| 汕尾市|