隨筆-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 閱讀(1293) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 石首市| 雷山县| 凤阳县| 德钦县| 溆浦县| 溧阳市| 昌吉市| 吉首市| 阿瓦提县| 句容市| 海丰县| 淳化县| 蛟河市| 宜君县| 且末县| 娱乐| 兴和县| 柳河县| 安图县| 广平县| 佳木斯市| 淮阳县| 郴州市| 滁州市| 丰宁| 东丽区| 通江县| 衡山县| 平泉县| 永州市| 武强县| 比如县| 嘉禾县| 灌南县| 新津县| 神木县| 湘西| 叶城县| 淮北市| 团风县| 温泉县|