计算机二级

3773考试网计算机等级考试计算机二级正文

完整操作ini文件的Java类

来源:fjzsksw.com 2010-7-19 14:53:26

 

private void myCopy() { // make a new list and just use this list later;

  String[] temp = { ";", ";" };

  for (int i = 0; i < this.inList.size(); i++) {

  temp[0] = this.inList.get(i).toString().trim();

  // System.out.println("#"+temp[0]);

  if (temp[0].equals("")) {

  this.outList.add(temp[1] + "?");

  } else if (temp[0].matches("\\[\\s*.*\\s*\\]")) {

  this.outList.add(temp[0]);// System.out.println("ok1");

  } else if (temp[0].matches("[a-zA-Z0-9]+=+.*")) {

  temp = this.inList.get(i).toString().split("=");

  this.outList.add(temp[0].trim() + "=" + temp[1].trim());// System.out.println("ok2");

  } else if(!temp.equals("")){

  this.outList.add(temp[0]);

  }else{

  this.outList.add(temp[0]);

  }

  }

  }

  public void myClear() {

  tagList.clear();

  }

  // mySearch();

  private int[] mySearch(String[] args) { // args = {section, variable}

  int max = this.outList.size();

  char ch;

  String str;

  int[] j = { -1, -1 };

  for (int i = 0; i < max; i++) {

  if (this.outList.get(i).toString().matches(

  "\\[\\s*" + args[0] + "\\s*\\]")) { // 找到 section;

  j[0] = i;

  i = i + 1;

  while ((ch = (str = this.outList.get(i).toString())

  .toCharArray()[0]) != '[') {

  // System.out.println("$"+str);

  if (ch != ';') {

  if (str.split("=")[0].equals(args[1])) { // 找到

  // variable;

  j[1] = i;

  break; // break out while();

  } else if (i < max - 1) {

  i = i + 1;

  } else {

  break; // break out while();

  }

  } else {

  i = i + 1;

  }

  }

  break;

  }

  }

  return j;

  }

  public int[] mySearch(String section, String variable) {

  String[] temp = { section, variable };

  int[] j = this.mySearch(temp);

  return j;

  }

  // end mySearchOne();

  // myGetOne();

  public int myGetNum(String section){

  int max = this.inList.size();

  String str;

  int num=0;

  for (int i = 0; i < max; i++) {

  if (this.inList.get(i).toString().matches(

  "\\[\\s*" + section + "\\s*\\]")) { // 找到 section;

  i = i + 1;

  while (!(this.inList.get(i).toString()).substring(0,1).equals("[")) {

  i=i+1;

  num+=1;

  }

  break;

  }

  }

  System.out.print("++++"+num+"++++");

  return num;

  }

 

上一页  [1] [2] [3] [4] 下一页

触屏版 电脑版
3773考试网 琼ICP备12003406号-1