The format of the file has many kinds of *.ini generally is a configuration file with a gear, the operation of this file has a special class library to handle the hard code itself Ini4j.jar
This jar package specifically encapsulates the method for handling *.ini files.
1 Public InterfaceIparamanager {2 Public intGetKey (string section, string key, CInt value);3 Public intgetkey (string section, string key, CString value);4 Public intgetkey (string section, string key, cdouble value);5 PublicMap<string, string>Getgeys (String section);6 Public intSetkey (string section, string key, String value);7 8}
1 Public classCfileparamanagernewImplementsIparamanager {2 3 PrivateLogger Logger = Logger.getlogger (Cfileparamanager.class);4Wini ini =NULL;5 PublicCfileparamanagernew (String fileName)throwsexception{6 String path = System.getproperty ("User.dir");//Parameter pending 7 String FilePath = path + File.separator + "R esources "+file.separator + fileName; 8 Logger.debug ("FilePath is" + FilePath); 9 Config config = new config (); Ten config.setmultisection (TRUE); One ini = new Wini (new File (FilePath)); A } - @Override - Public intGetKey (string section, string key, CInt value) { theLogger.debug ("Cfileparamanager getKey CInt Start"); -String str =integer.valueof (Value.get ()). ToString (); -CString CString =NewCString (); - Cstring.set (str); + intnum =getkey (section, key, cString); - if(num! = 0) { +Logger.debug ("Cfileparamanager GetKey CInt fail"); A return-1; at } - intval =Integer.parseint (Cstring.get ()); - Value.set (val); -Logger.debug ("Cfileparamanager getKey CInt End"); - return0; - } in - @Override to Public intgetkey (string section, string key, CString value) { +Logger.debug ("Cfileparamanager getKey CString Start"); - if(NULL= = Section | |NULL==key) { theLogger.debug ("Cfileparamanager getKey CString start section or key or value is null"); * return-1; $ }Panax NotoginsengLogger.debug ("section was" + "+ section +" "+" key is "+" "+key); - Config config = new config (); the config.setmultisection (true); + String revalue = ini.get (section, key, String.class); A if(Revalue = =NULL) { theLogger.debug ("Revalue is null"); + return-1; - } $ Value.set (revalue); $ return0; - - } the - @OverrideWuyi Public intgetkey (string section, string key, cdouble value) { theLogger.debug ("Cfileparamanager getKey cdouble Start"); -String str =double.valueof (Value.get ()). ToString (); WuCString CString =NewCString (); - Cstring.set (str); About intnum =getkey (section, key, cString); $ if(num! = 0) { -Logger.debug ("Cfileparamanager GetKey cdouble fail"); - return-1; - } A Doubleval =double.parsedouble (Cstring.get ()); + Value.set (val); theLogger.debug ("Cfileparamanager getKey cdouble End"); - return0; $ the } the @Override the PublicMap<string, string>Getgeys (String section) { theLogger.debug ("Cfileparamanager getgeys section start"); - if(Section = =NULL|| Section.length () = = 0) { inLogger.debug ("Cfileparamanager getgeys section isn't normal"); the } the map<string, string> sections = ini.get (section); AboutLogger.debug ("Cfileparamanager getgeys section end"); the returnsections; the } the @Override + Public intSetkey (string section, string key, String value) { -Logger.debug ("Cfileparamanager setkey section start"); the if(Section = =NULL|| Key = =NULL|| Value = =NULL) {BayiLogger.debug ("setction or key or value is not normal"); the return-1; the } - //ini.add (section, key, value); -Logger.debug ("Cfileparamanager setkey section end"); the //If section is modified, nothing is created. the ini.put (section, key, value); the //2018/10/9 This code does not add to the change does not play any role89try {ini.store (); (IOException e) {//TODO auto-generated catch bl Ock E.printstacktrace (); 94} the //ini.get (section, key); the the return0;98 } About -}
Refer to Wiki:
https://www.vdisk.cn/ini4j/(Summary of Ini4j.jar Resources)
48973307 (To change the properties file additions and deletions)
25059931 (Operation of the *ini file Two tool methods one original method)
49994413# (*ini for getting started with file operations small demo)
Https://www.programcreek.com/java-api-examples/index.php?api=org.ini4j.InvalidFileFormatException (Not read But the demo is really a lot.)
*.ini file additions and deletions to change the search