/** */ /**
  * 修改ini配置文件中变量的值
  * @param file 配置文件的路径
  * @param section 要修改的变量所在段名称
  * @param variable 要修改的变量名称
  * @param value 变量的新值
  * @throws IOException 抛出文件操作可能出现的io异常
  */
  public   static   boolean  setProfileString(
  String file,
  String section,
  String variable,
  String value)
  throws  IOException  {
  String fileContent, allLine,strLine, newLine, reStr;
  String getValue;
  System.out.println(file);
  BufferedReader bufferedReader  =   new  BufferedReader( new  FileReader(file));
  boolean  isInSection  =   false ;
  fileContent  =   "" ;
  try   {
  
  while  ((allLine  =  bufferedReader.readLine())  !=   null )  {
 allLine  =  allLine.trim();
 if  (allLine.split( "[;] " ).length  >   1 )
 reStr  =   ";"   +  allLine.split( " ; " )[ 1 ];
 else
 reStr  =   "";
 strLine  =  allLine.split( " ; " )[ 0 ];
 Pattern p;
 Matcher m;
 p  =  Pattern.compile( " file://[//s*.*//s*//] " );
 m  =  p.matcher((strLine));
 if  (m.matches())  {
 p  =  Pattern.compile( " file://[//s* "   +  section  +   " file://s*//] " );
 m  =  p.matcher(strLine);
 if  (m.matches())  {
 isInSection  =   true ;
 }   else   {
 isInSection  =   false ;
 }
 }
 if  (isInSection  ==   true )  {
 strLine  =  strLine.trim();
 String[] strArray  =  strLine.split( "=" );
 getValue  =  strArray[ 0 ].trim();
 if  (getValue.equalsIgnoreCase(variable))  {
 newLine  =  getValue  +   "="   +  value  +   "   "   +  reStr;
 fileContent  +=  newLine  +  " \r\n " ;
 while  ((allLine  =  bufferedReader.readLine())  !=   null )  {
 fileContent  +=  allLine  +   " \r\n " ;
 }
 bufferedReader.close();
 BufferedWriter bufferedWriter  =
 new  BufferedWriter( new  FileWriter(file,  false ));
 bufferedWriter.write(fileContent);
 bufferedWriter.flush();
 bufferedWriter.close();
  
 return   true ;
 }
 }
 fileContent  +=  allLine  +   " \r\n " ;
 }
 } catch (IOException ex) {
 throw  ex;
 }   finally   {
 bufferedReader.close();
 }
 return   false ;
 }
  
  /** */ /**
  * 程序测试
  */
  public   static   void  main(String[] args)  {
  try   {
  System.out.println(ConfigurationFile.setProfileString( "d:/1.ini" ,  "11" ,  "22" ,  "111" ));
  }   catch  (IOException e)  {
  System.out.println(e.toString());
  }
  }  d:/1.ini为
[11]
22=xx代码是网上找的,基本上网上都是这个代码,为什么每次返回都是false
不太懂JAVA,求教!