java里面有没有专门用来读配置文件的方法 java.util.Properties 类里有些方法,专门处理配置文件,你可以看看。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 除了使用Properties外,还可以通过File和BufferedReader将ini文件读取出来,读出后还能够做进一步的处理 String recordsPerPage="0"; properties = new Properties(); InputStream is = null; try{ is = getClass().getResourceAsStream("/../pbcenter.properties"); properties.load(is); } catch(Exception e) { System.out.println("Can't read properties file"); } finally { try{ if(is != null) is.close(); } catch(IOException e) { //ignore } } recordsPerPage=properties.getProperty("SYS.RECORDS_PER_PAGE"); 看看Properties类,应该能给你帮助的。楼上的代码应该可用。 try{ ResourceBundle rb = ResourceBundle.getBundle("SmsSC"); this.Sms_IP=rb.getString("Sms_IP"); this.Sms_Port=rb.getString("Sms_Port"); }catch(Exception e){ System.err.println("读取系统配置信息失败了!请确定文件MailSC.properties是否存在!错误:" + e.getMessage()); } config文件DBdriver=com.microsoft.jdbc.sqlserver.SQLServerDriverDBConfig=jdbc:microsoft:sqlserver://gwserver3:1433;databasename=train,train,'',MAXConnection=50读取private void readConfig(String cfgfile) { Properties pps = new Properties() ; try { BufferedReader in = new BufferedReader(new FileReader(cfgfile)); String s = null ; while ((s = in.readLine()) != null ) { int iLoc = s.indexOf('=') ; if (iLoc >= 0) { System.out.println(s); pps.put(s.substring(0,iLoc).toLowerCase().trim(),s.substring(iLoc+1).trim()); } } in.close(); } catch (FileNotFoundException e) { System.out.println("basefun.readconfig:"+e); } catch (IOException e){ System.out.println("basefun.readconfig:"+e); } String strDriver = (String) pps.get("dbdriver") ; String strDbcfg = (String) pps.get("dbconfig") ; String strMaxcon = (String) pps.get("maxconnection") ; int iMaxcon = Integer.parseInt(strMaxcon) ; String strOpFile = (String) pps.get("opfile") ; String strChnFile = (String) pps.get("chndicfile") ; Pool = new ConnectionPool(strDriver,strDbcfg,iMaxcon) ;// Pool.run() ;// initChnDic(strChnFile) ; //文件形式存放的中文字典表// initChnDic() ; //数据库形式存放的中文字典表// Oplist = new OPList(Pool); //数据库形式存放的数据库操作步骤表-------lijian 先禁掉,以后再用2002-06-04// Oplist = new OPList(strOpFile); //文件形式存放的数据库操作步骤表 initTableDic() ; } 一道面试题,我不会呵呵。各位帮忙看下 JAVA关于equals的问题 平方根用哪个函数啊? 请高手帮我解说下代码 大吓指教java 好奇怪的字节和string阿 如何用tomcat 捕获异常 我已经引用一下两个库文件,但还是有错啊?到低是怎么回事? $$$ 如果在JAVA程序中执行磁盘上的一个程序? $$$ 请问谁有《java2核心技术 卷I:基础知识》书中例子的源代码?急需!!! JavaMail发送邮件问题!急! 请教同一包内类的访问权限!怎么调试也出错!!!!
properties = new Properties();
InputStream is = null;
try{
is = getClass().getResourceAsStream("/../pbcenter.properties");
properties.load(is);
} catch(Exception e) {
System.out.println("Can't read properties file");
} finally {
try{
if(is != null)
is.close();
} catch(IOException e) {
//ignore
}
}
recordsPerPage=properties.getProperty("SYS.RECORDS_PER_PAGE");
ResourceBundle rb = ResourceBundle.getBundle("SmsSC");
this.Sms_IP=rb.getString("Sms_IP");
this.Sms_Port=rb.getString("Sms_Port");
}catch(Exception e){
System.err.println("读取系统配置信息失败了!请确定文件MailSC.properties是否存在!错误:" + e.getMessage());
}
DBdriver=com.microsoft.jdbc.sqlserver.SQLServerDriver
DBConfig=jdbc:microsoft:sqlserver://gwserver3:1433;databasename=train,train,'',
MAXConnection=50读取private void readConfig(String cfgfile) { Properties pps = new Properties() ; try {
BufferedReader in = new BufferedReader(new FileReader(cfgfile));
String s = null ;
while ((s = in.readLine()) != null ) {
int iLoc = s.indexOf('=') ;
if (iLoc >= 0) {
System.out.println(s);
pps.put(s.substring(0,iLoc).toLowerCase().trim(),s.substring(iLoc+1).trim());
}
}
in.close();
}
catch (FileNotFoundException e) {
System.out.println("basefun.readconfig:"+e);
}
catch (IOException e){
System.out.println("basefun.readconfig:"+e);
} String strDriver = (String) pps.get("dbdriver") ;
String strDbcfg = (String) pps.get("dbconfig") ;
String strMaxcon = (String) pps.get("maxconnection") ;
int iMaxcon = Integer.parseInt(strMaxcon) ; String strOpFile = (String) pps.get("opfile") ;
String strChnFile = (String) pps.get("chndicfile") ; Pool = new ConnectionPool(strDriver,strDbcfg,iMaxcon) ;
// Pool.run() ;// initChnDic(strChnFile) ; //文件形式存放的中文字典表
// initChnDic() ; //数据库形式存放的中文字典表// Oplist = new OPList(Pool); //数据库形式存放的数据库操作步骤表-------lijian 先禁掉,以后再用2002-06-04
// Oplist = new OPList(strOpFile); //文件形式存放的数据库操作步骤表
initTableDic() ; }