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

📄 inireader.java

📁 我自己写的
💻 JAVA
字号:
import   java.util.*;   
import   java.io.*;   
  /**   
    *   <title>   IniReader   
    *   <description>     
    *   <company>   
    *   @author   rock       
    *2007-5-9   
    */   
  public   class   IniReader   
  {   
	  protected   LinkedHashMap   sections;     //使用   
    
	  public   IniReader()   
	  {   
		  	super();   
		  	sections   =   new   LinkedHashMap();   
	  }   
    
	  public   Map   getSections()   
	  {   
		  	return   sections;   
	  }   
    
	  public   Map   getSection(String   sectionName)   
	  {   
		  	if(sections   !=   null)   
		  		return   (Map)sections.get(sectionName);   
		  	else   
		  		return   null;   
	  }     
    
	  public   void   load(String   fileName)   throws   FileNotFoundException   
	  {   
		  InputStream   is   =   null;   
		  try   
		  {   
			  is   =   new   FileInputStream(fileName);   
			  load(is);   
		  }catch   (IOException   e) 
		  {   
			  e.printStackTrace();   
		  }finally   
		  {   
			  if(is!=null)   try{ is.close(); } catch   (IOException   e1) {}     
		  }   
	  }   
    
	  public   void   load(InputStream   is)   throws   IOException   
	  {   
		  BufferedReader   reader   =   new   BufferedReader(new   InputStreamReader(is));   
		  String   line   =   null;       
		  String   lastSectionName   =   null;     
		  while(   (line   =   reader.readLine())   !=   null)   
		  {   
			  line   =   line.trim();   
			  if(line.startsWith("[")   &&   line.endsWith("]"))   
			  {   
				  lastSectionName   =   line.trim().substring(1,line.length()-1);   
				  sections.put(lastSectionName   ,   new   LinkedHashMap());     //创建一个section   
			  }else   if(line.length()   ==   0)   
			  {   
				  continue;   
			  }else   
			  {   
				  if(lastSectionName!=null)   
				  {   
					  Map   section   =   (Map)sections.get(lastSectionName);   
					  int   index   =   line.indexOf('=');   
					  String   key   =   index   >   0   ?   line.substring(0,index)   :   line;     //如果没有等号,直接做key和value   
					  String   value   =   index   >   0   ?   line.substring(index   +1)   :   line;   
					  section.put(key,value);   
				  }   
			  }   
		  }   
	  }   
    /*
	  public   static   void   main(String[]   args)   
	  {   
		  IniReader   iniReader   =   new   IniReader();   
		  try   
		  {   
			  iniReader.load("D:/IRMS.ini");   
			  Map   sections   =   iniReader.getSections();   
			  Map   section1   =   (Map)sections.get("Composers");   
			  System.out.println("key1:"   +   section1.get("LocalFiles"));   
		  }   
		  catch   (IOException   e)   
		  {   
			  //   TODO   Auto-generated   catch   block   
			  e.printStackTrace();   
		  }   
	  }   */
  	}   
  

⌨️ 快捷键说明

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