📄 config_ini.java
字号:
package com.hxyh.sanny.mms.telecom.tool;
import java.io.*;
public class Config_ini {
private String fileName = null;
private BufferedReader readBuffer;
private PrintWriter writeBuffer;
private String[] lineBuffer=new String[1000];
private int lineNumber=0;
private int startline;
private String Temp;
public Config_ini(String fileName) {
this.fileName = fileName;
try{
readBuffer = new BufferedReader(new InputStreamReader(new FileInputStream(this.fileName)));
}
catch(FileNotFoundException e){
e.printStackTrace(System.out);
System.out.println("打开文件失败!");
}
while(readLine()){
lineBuffer[lineNumber] = Temp;
lineNumber++;
}
try {
readBuffer.close();
}
catch (IOException e) {
System.out.println(e);
}
}
public boolean readLine(){
try {
if ((Temp=readBuffer.readLine()) != null){
Temp = Temp.trim();
}
else{return false;}
}
catch (IOException e) {
e.printStackTrace(System.out);
return false;
}
return true;
}
public String readAttribute(String subNote,String TextNote){
String subNoteText = "["+subNote+"]";
String TextNoteText = TextNote;
String TextValue=null;
for (int i=0;i<lineNumber;i++){
if (lineBuffer[i].equals(subNoteText))
startline = i;
}
for (int i=startline+1;i<lineNumber;i++){
if (lineBuffer[i].substring(0,lineBuffer[i].indexOf("=")).equals(TextNoteText)){
TextValue = lineBuffer[i].substring(lineBuffer[i].indexOf("=") + 1,
lineBuffer[i].length());
break;
}
}
return TextValue;
}
public void setAttribute(String subNote,String TextNote,String TextNoteValue)
{
String subNotew = "["+subNote+"]";
String strValue;
boolean boosubNote = false;
File f = new File(this.fileName);
f.delete();
try{
writeBuffer=new PrintWriter(new FileWriter(this.fileName,true));
for(int i=0;i<lineNumber;i++){
if (lineBuffer[i].equals(subNotew))
boosubNote = true;
if (lineBuffer[i].indexOf(TextNote)>=0 && boosubNote){
strValue = lineBuffer[i].substring(0, lineBuffer[i].indexOf("=") + 1) + TextNoteValue;
boosubNote = false;
}
else
strValue = new String(lineBuffer[i]);
writeBuffer.println(strValue);
}
writeBuffer.close();
}
catch(FileNotFoundException e){
System.out.println(e);
}
catch(IOException e){
System.out.println(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -