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 阅读(1277)
评论(0) 编辑 收藏 所属分类:
Java