当前位置: 技术问答>java相关
您有管理配置文件的Java原码以及类吗??
来源: 互联网 发布时间:2015-06-25
本文导语: 如果您能够提供的话,不胜感激!救命用的! | import java.io.*; import java.util.*; public class IniFileHandler { private LinkedList lstContentLine; public IniFileHandler() { init(); } public IniFileHandler(String f...
如果您能够提供的话,不胜感激!救命用的!
|
import java.io.*;
import java.util.*;
public class IniFileHandler
{
private LinkedList lstContentLine;
public IniFileHandler()
{
init();
}
public IniFileHandler(String filepath,boolean bcreate)
{
sFilePath = filepath;
init();
}
private void init()
{
//used in the constructor
lstContentLine = new LinkedList();
}
public void create() throws Exception
{
//read the ini file into this object
File f = new File(getFilePath());
FileInputStream fis = new FileInputStream(f);
DataInputStream di = new DataInputStream(fis);
String line = di.readLine();
while(line!=null)
{
line = trimLine(line);
if(line!=null)
lstContentLine.add(line);
line = di.readLine();
}
di.close();
}
private String trimLine(String s)
{
//remove leading spaces of the line
//remove spaces before "="
if(s==null)
return s;
String s_raw = s;
s = s.trim();
if(s==null)
return s_raw;
int npos=s.indexOf("=");
if(npos
import java.util.*;
public class IniFileHandler
{
private LinkedList lstContentLine;
public IniFileHandler()
{
init();
}
public IniFileHandler(String filepath,boolean bcreate)
{
sFilePath = filepath;
init();
}
private void init()
{
//used in the constructor
lstContentLine = new LinkedList();
}
public void create() throws Exception
{
//read the ini file into this object
File f = new File(getFilePath());
FileInputStream fis = new FileInputStream(f);
DataInputStream di = new DataInputStream(fis);
String line = di.readLine();
while(line!=null)
{
line = trimLine(line);
if(line!=null)
lstContentLine.add(line);
line = di.readLine();
}
di.close();
}
private String trimLine(String s)
{
//remove leading spaces of the line
//remove spaces before "="
if(s==null)
return s;
String s_raw = s;
s = s.trim();
if(s==null)
return s_raw;
int npos=s.indexOf("=");
if(npos