⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ini.java

📁 是一个应用型java网站例子
💻 JAVA
字号:
// INI类,用于对参数文件的管理

package com.neck;

import java.io.*;
import java.util.*;


public class Ini{

	String			m_strIniFile;
	String			m_strErrMsg;
	int				m_iCount;			//	记录总数

	public Ini(String strIniFile)
	{
		if( strIniFile == null )
			m_strIniFile	=	"C:\\teloa.ini";
		else
			m_strIniFile	=	strIniFile;
	}
	

	/*****************************************************************************************
	**	功能:	取出某个应用下某项的配置参数												**
	**	输入:	strAppName--应用名					strKeyName--参数名						**
	**	输出:	取出的字串(取不到则为空)													**
	**	Auth:	Ysr																			**
	**	Date:	2004.5.10																	**
	******************************************************************************************/
	public String getString(String strAppName, String strKeyName)	
	{
		InputStream		m_InStream;
		BufferedReader	m_Reader;
		String			m_strVal	=	null;
		
		try{
			m_InStream		=	new FileInputStream(m_strIniFile);
			m_Reader		=	new BufferedReader(new InputStreamReader(m_InStream));
		}
		catch(FileNotFoundException ex)
		{
			m_strErrMsg	=	"打开文件出错,请检查文件:" + m_strIniFile + "是否存在!";
System.out.println("FileNotFoundException!!msg=" + ex.getMessage() );
			return null;
		}

		try{
			String		strTmp;
			boolean		bApp	=	false;
			int			i;
			while(true)
			{
				strTmp	=	m_Reader.readLine();
				if( strTmp == null )	break;					
				else					strTmp	=	strTmp.trim();
				
				
				// 比较AppName
				if( bApp == false )
				{
					if( strTmp.charAt(0)	==	'[' )
					{

						if( strTmp.substring(1,strTmp.length()-1).equalsIgnoreCase(strAppName) )
							bApp	=	true;					
					}
					continue;
				}
				
				
				// 判断KEY值
				i	=	strTmp.indexOf("=");
				if( i == -1 )		continue;
				if( strTmp.substring(0,i).trim().equalsIgnoreCase(strKeyName) )
				{
					m_strVal	=	strTmp.substring(i+1,strTmp.length());
					break;
				}
			}
			m_Reader.close();
			m_InStream.close();
		}
		catch( IOException ex )
		{
			m_strErrMsg	=	ex.getMessage();
System.out.println(m_strErrMsg);
				
		}	
		return m_strVal;
	}


	/*****************************************************************************************
	**	功能:	取出某个应用下某项的配置参数												**
	**	输入:	iPageNum : 当前页;iPerPageRow:每页行数									**
	**	输出:	取出列表																	**
	**	Auth:	Ysr																			**
	**	Date:	2004.9.2																	**
	******************************************************************************************/
	public Collection getRecordList(int iPageNum, int iPerPageRow)	
	{
		Vector<IniData> RecordList = new Vector<IniData>();
		InputStream		m_InStream;
		BufferedReader	m_Reader;
		
		int				iBeginPos	=	(iPageNum-1)*iPerPageRow+1;
		int				iEndPos		=	iPageNum*iPerPageRow;
		
		try{
			m_InStream		=	new FileInputStream(m_strIniFile);
			m_Reader		=	new BufferedReader(new InputStreamReader(m_InStream));
		}
		catch(FileNotFoundException ex)
		{
			m_strErrMsg	=	"打开文件出错,请检查文件:" + m_strIniFile + "是否存在!";
System.out.println("FileNotFoundException!!msg=" + ex.getMessage() );
			return null;
		}

		try{
			String		strTmp;
//			boolean		bApp	=	false;
			int			i;
			
			String		strSystemName	=	"";		//	子系统名
			String		strParaName		=	"";		//	参数名
			String		strParaVal		=	"";		//	参数值
			m_iCount					=	0;
			
			while(true)
			{
				strTmp	=	m_Reader.readLine();
				if( strTmp == null || strTmp.trim().equals("") )	break;					
				else					strTmp	=	strTmp.trim();
				
				
				if( strTmp.charAt(0)	==	'[' )
				{
					strSystemName	=	strTmp.substring(1,strTmp.length()-1 );
					continue;
				}
				else
				{
					// 判断KEY值
					i	=	strTmp.indexOf("=");
					if( i == -1 )		continue;
					
					strParaName		=	strTmp.substring(0,i);
					strParaVal		=	strTmp.substring(i+1,strTmp.length());
					
					m_iCount++;

					// 加入到列表中
					if( iBeginPos <= m_iCount && m_iCount <= iEndPos )
					{
						IniData pIniData = new IniData(strSystemName, strParaName,strParaVal);
						RecordList.addElement(pIniData);
					}
				}					
			}
			m_Reader.close();
			m_InStream.close();
		}
		catch( IOException ex )
		{
			m_strErrMsg	=	ex.getMessage();
System.out.println(m_strErrMsg);
				
		}	
		return RecordList;
	}


	public int getCount()
	{
		return m_iCount;
	}

	public String getErrMsg()
	{
		return this.m_strErrMsg;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -