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 閱讀(1281)
評論(0) 編輯 收藏 所屬分類:
Java